We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Child Categories

Development and Programming

Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi drpudding,

Download version 2.0 - it supports {child_category_id} variable inside {entries_wrapper_top_start}{entries_wrapper_top_end} and {entries_wrapper_bottom_start}{entries_wrapper_bottom_end} variable pairs.

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi all,

I released version 2.0 of Child categories plugin (versions 1.7 - 1.9 were not released publicly).

New features:

1) “category_group” optional parameter. It allows you to specify category group id number (the id number of each category group is displayed in the Control Panel). In case this parameter is defined, all highest level categories of that category group will be treated by plugin as parent categories.

2) “parent_categories_sort_by” optional parameter. For use together with “category_group” parameter. Allows you to specify sort order of parent categories. This parameter accepts three values: “name” (parent categories will be sorted by name), “id” (parent categories will be sorted by id number), and “custom” (parent categories will be sorted using custom order as defined in control panel). Default value is “name”.

3) “parent_categories_sort_direction” optional parameter. For use together with “category_group” parameter. Allows you to specify sort direction of parent categories. This parameter accepts two values: “asc” and “desc”. Default value is “asc”.

4) support for {entries_total} and {child_category_id} variables inside {entries_wrapper_top_start}{entries_wrapper_top_end} variable pair.

5) support for {entries_total} and {child_category_id} variables inside {entries_wrapper_bottom_start}{entries_wrapper_bottom_end} variable pair.

6) support for {entries_total} and {child_category_id} variables inside {child_wrapper_bottom_start}{child_wrapper_bottom_end} variable pair.

7) support for {parent_category_children_count} and {parent_category_id} variables inside {parent_wrapper_bottom_start}{parent_wrapper_bottom_end} variable pair.

       
drpudding's avatar
drpudding
58 posts
16 years ago
drpudding's avatar drpudding

Thanks for the fantastic support on this plug in, Laisvunas! 2.0 certainly solved my problem with removing those useless <div>s

FYI – I was never able to figure out why the plugin doesn’t render <ol>, <ul>, and <li> when setting field_format to XHTML. Works fine with other tags (e.g. <strong>).

Not a big deal to work around, but it is curious.

Thanks, again.

       
drpudding's avatar
drpudding
58 posts
16 years ago
drpudding's avatar drpudding

Laisvunas –

I’m using the single field tag to display custom field data inside the child categories tag, like so:

{entries_start}
    City: {exp:single_field field="f_city" weblog="{my_weblog}" entry_id="{entry_id}" field_format="raw"}
    State: {exp:single_field field="f_state" weblog="{my_weblog}" entry_id="{entry_id}" field_format="raw"}
{entries_end}

Is there any way to add a conditional to only show custom field data, if that data exists? Something that is common with the weblog entries tag, such as:

{if f_city}City: {f_city}{/if}
       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi drpudding,

Write the code as follows:

{entries_start}
    {if "{exp:single_field field="f_city" weblog="{my_weblog}" entry_id="{entry_id}"}"}City: {exp:single_field field="f_city" weblog="{my_weblog}" entry_id="{entry_id}" field_format="raw"}{/if}
    {if "{exp:single_field field="f_state" weblog="{my_weblog}" entry_id="{entry_id}"}"}State: {exp:single_field field="f_state" weblog="{my_weblog}" entry_id="{entry_id}" field_format="raw"}{/if}
{entries_end}
       
drpudding's avatar
drpudding
58 posts
16 years ago
drpudding's avatar drpudding

Thank you, Laisvunas. I’m seeing some errors with my code and I wonder if you know why. Parse order? Here is the code:



As you can see, there are 3 different conditions, depending on whether segments 3 or 2 are present.

The code works fine for {if segment_3} or {if segment_2}, but when these segments are missing, it does not find the final {if:else}. Instead it gets trapped in the {if segment_3} condition. I am getting Invalid EE Conditional Variable errors & syntax error, unexpected T_STRING in the {entries_start}{entries_end} loop, suggesting a possible end bracket or quote issue. I have stared at the code but cannot see any problem with it, or see why it is getting caught in {if segment_3}.

One odd thing is that when I write this line into the href in {segment_3} code block above, it doesn’t render fully. Not sure if that has something to do with it:

{exp:single_field field="r_url" weblog="{my_weblog}” entry_id=”{entry_id}”}

Is this a parsing issue?

I’m also wondering if this use of so many multiple plugins and conditions ends up being less efficient than the weblog entries tag.

Thanks!

       
elemental's avatar
elemental
77 posts
16 years ago
elemental's avatar elemental

Just want to say thank you, Laisvunas.

I have used this plugin on a ongoing project with the jQuery UI accordion with great success. So as inspiration or just heads up for anyone I am attaching the code. It was simple to implement, great plugin. 😊 The Low’s seg2cat is also used to get the ID of the category from segment_1.

<div id="sidebar">
    <h2>{exp:title:category url_title="{segment_1}"} listing</h2>
    <div id="submenu">
        {exp:child_categories parent="{segment_1_category_id}" child_categories_sort_by="custom" show_empty="yes"}
        {child_category_start}
        <h3>{child_category_name}</h3>{child_category_end}
        {entries_wrapper_top_start}
        <ul>{entries_wrapper_top_end}
        {entries_start}
        <li{if "{url_title}" == "{segment_3}"} class="current"{/if}><a href="http://{path=}{parent_category_url_title}/{child_category_url_title}/{url_title}">{title}</a></li>{entries_end}
        {entries_wrapper_bottom_start}
        </ul>
        {entries_wrapper_bottom_end}
        {/exp:child_categories}
    </div>
</div>

and the jquery code for the UI accordion

$('#submenu').accordion({ autoHeight: false , navigation: true });

The “navigation: true” parameter looks for the anchor that matches location.href and activates it.

See the result at (real content still missing) http://camphighland.elementalmedia.info/programs

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi drpudding,

It does not seem to have any relation to parsing order. Neither it seems to berelated to Child categories plugin. So, about this issue you would better ask tech support team.

Try instead of writing

{if segment_3}

{if:elseif segment_2}

{if:else}

{/if}

to write

{if segment_3}

{if:elseif segment_2}

{/if}

{if segment_2 == "" AND segment_3 == ""}

{/if}
       
drpudding's avatar
drpudding
58 posts
16 years ago
drpudding's avatar drpudding

Laisvunas,

Tried your suggestion, but it didn’t change anything. I know it has something to do with the {entries_start} loop in the first condition, since if I remove this code there it works fine:

<pre><code>

        {if "{exp:single_field field="r_url" weblog="{my_weblog}" entry_id="{entry_id}"}"}
            <a href="http://{exp:single_field" class="inlineLink" target="_blank" rel="noopener">_            {/if}_                {title}_            {if "{exp:single_field field="r_url" weblog="{my_weblog}" entry_id="{entry_id}"}"}</a>{/if}


        {if "{exp:single_field field="r_source" weblog="{my_weblog}" entry_id="{entry_id}"}"}<strong>Source:</strong> {exp:single_field field="r_source" weblog="{my_weblog}" entry_id="{entry_id}" field_format="raw"}{/if}
        {if "{exp:single_field field="r_description" weblog="{my_weblog}" entry_id="{entry_id}"}"}<strong>Description:</strong> {exp:single_field field="r_description" weblog="{my_weblog}" entry_id="{entry_id}" field_format="raw"}{/if}[/code]

Not sure if you saw this note on my last entry, which I had just added:

When I write this line into the href in {segment_3} code block above, it doesn’t render fully. Not sure if that has something to do with it:

{exp:single_field field=“r_url” weblog=”{my_weblog}” entry_id=”{entry_id}”}

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi drpudding,

I have no more suggestions, only this: start from the code

{if segment_3 != ""}

{if:elseif segment_2 !=""}

{if:else}

{/if}

and add all other code one piece a time thoroughly checking if it works after each addition. This way you may find a culprit or/and working solution.

       
drpudding's avatar
drpudding
58 posts
16 years ago
drpudding's avatar drpudding

I will see if I can isolate the issue by dismantling the script. Technical support asked that I refer this issue back to you, since I am using three of your plug ins. I may have to abandon my current approach.

One interesting issue is that one of the single fields, r_url, in the first condition stores urls (http://…) They are rendered fine when that condition is not met, but when it’s not met, they are responsible for the Invalid EE Conditional Variable errors. I know this, since that error disappears when I just use a simple text string for that data. (Weblog is not set to auto-covert URLs). It doesn’t solve the unexpected T_STRING error.

Will keep trying. Thanks.

       
Wes Baker's avatar
Wes Baker
343 posts
16 years ago
Wes Baker's avatar Wes Baker

What would it take to get the {pages_url} or {pages_uri} info into the {entries_start} loop?

       
drpudding's avatar
drpudding
58 posts
16 years ago
drpudding's avatar drpudding

Laisvunas –

I wonder if you might be able to tell me why this code is resulting in about 40 extra SQL queries:

{exp:child_categories sibling="37|38" weblog="resources" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="no" entries_limit="none" status="open"}
{child_category_start}
<li><h2>{child_category_name}</h2></li>
{child_category_end}
{entries_start}
<li><div class="nonCurrent"><a href="http://{path=resources}C{child_category_id}/{url_title}">{title}</a></div></li>
{entries_end}
{/exp:child_categories}

The weblog “resources” has only 2 categories (37, 38) and only 9 entries.

Below is a sample of one of the 40+ extra queries. They are all identical, except for the part: exp_category_posts.cat_id=’12’. 12 is not even one of the categoriees in the ‘resources’ weblog. Several othr non-resource categories are in these queries, and several are repeated in identical queries more than once.

SELECT exp_weblog_titles.entry_id, exp_weblog_titles.url_title, exp_weblog_titles.title, exp_weblog_titles.entry_date, exp_weblog_titles.site_id, exp_weblog_titles.status, exp_weblog_titles.expiration_date, exp_weblogs.blog_name, exp_weblogs.blog_title, exp_weblogs.blog_url, exp_categories.cat_name, exp_categories.cat_id, exp_categories.cat_url_title FROM exp_category_posts, exp_weblog_titles, exp_weblogs, exp_categories WHERE exp_category_posts.entry_id=exp_weblog_titles.entry_id AND exp_weblog_titles.weblog_id=exp_weblogs.weblog_id AND exp_category_posts.cat_id=exp_categories.cat_id AND exp_weblog_titles.site_id=exp_categories.site_id AND exp_category_posts.cat_id='12' AND exp_weblogs.blog_name='resources' AND exp_weblog_titles.status='open' ORDER BY exp_weblog_titles.entry_date DESC

The code renders correctly – showing the 9 entries in the 2 categories of “resources.” But why all those extra queries?

Thanks!

Marc

       
LucPestille's avatar
LucPestille
146 posts
16 years ago
LucPestille's avatar LucPestille

I’ve run into a problem that I think might be down to the way the loop is run, http://ellislab.com/forums/viewthread/113701/ - but I’m probably more likely to get an answer here;

{exp:child_categories category_group="3"}

    {parent_category_start}
    <h2>{parent_category_name}</h2>
    <ul class="filter">
    {parent_category_end}
            

    {parent_wrapper_bottom_start}</ul>{parent_wrapper_bottom_end}

    {child_category_start}
    <li {if {child_category_url_title}=={segment_4} }class="selected"{/if}><a href="http://{homepage}gallery/view/category/{child_category_url_title}/">{child_category_name}</a></li>
    {child_category_end}

{/exp:child_categories}

I can’t get the if statement in {child_category_start} to work, it’s as if it finds a true value at some point in the loop and applies it to every instance in that loop, instead of per run through. Printing out {segment_4} and {child_category_url_title} individually in the child category confirms that they’re different for all but one, but the loop works as if it’s always the same. Make sense? Any ideas?

Thanks,

       
Omma Creative's avatar
Omma Creative
26 posts
16 years ago
Omma Creative's avatar Omma Creative

I’ve tried everything I can imagine and read this thread and the subcategories thread front to back repeatedly to get this to work. All I need to do is:

Have a list of parent categories with their child categories (or subcategories, however it’s termed) produced dynamically. Then I want to be able to take these lists and use a jQuery accordion plug in to have only one parent and it’s children show at a time. Simple to do in standard HTML, but the way that Expression Engine and this plug in are set up is baffling, I cannot seem to get how to populate the data. Here’s the code as standard HTML, CSS, and jQuery:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >

<head>

<title>iwi fresh | Products</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

[removed][removed]
[removed]
function initMenus() {
    $('ul.menu ul').hide();
    $.each($('ul.menu'), function(){
        $('#' + this.id + '.expandfirst ul:first').show();
    });
    $('ul.menu li a').click(
        function() {
            var checkElement = $(this).next();
            var parent = this[removed][removed].id;

            if($('#' + parent).hasClass('noaccordion')) {
                $(this).next().slideToggle('normal');
                return false;
            }
            if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
                if($('#' + parent).hasClass('collapsible')) {
                    $('#' + parent + ' ul:visible').slideUp('normal');
                }
                return false;
            }
            if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                $('#' + parent + ' ul:visible').slideUp('normal');
                checkElement.slideDown('normal');
                return false;
            }
        }
    );
}
$(document).ready(function() {initMenus();});
[removed]

</head>

<body>
                    
<div id="leftcolumn">
<ul id="menu1" class="menu">
      <li>          
           <a href="#">Body</a>
                <ul>
                     <li><a href="http://www.iwifresh.com/newsite/index.php/products/list/category/body">Body > All Body Products</a></li>          
                     <li><a href="http://www.iwifresh.com/newsite/index.php/products/list/category/body_all_skin_types">Body > All Skin Types</a></li>
                </ul>
      </li>
      <li>          
           <a href="#">Face</a>
                <ul>          
                     <li><a href="http://www.iwifresh.com/newsite/index.php/products/list/category/face">Face > All Face Products</a></li>
                     <li><a href="http://www.iwifresh.com/newsite/index.php/products/list/category/face_dry_skin">Face > Dry Skin</a></li>
               </ul>

      </li>
      <li>          
           <a href="#">Feet</a>
                <ul>          
                     <li><a href="http://www.iwifresh.com/newsite/index.php/products/list/category/feet">Feet > All Feet Products</a></li>
                </ul>
      </li>
      <li>          
           <a href="#">Hair</a>
                <ul>     
                     <li><a href="http://www.iwifresh.com/newsite/index.php/products/list/category/hair">Hair > All Hair Products</a></li>     
                     <li><a href="http://www.iwifresh.com/newsite/index.php/products/list/category/hair_dry_to_normal">Hair > Dry to Normal</a></li>
                </ul>
      </li>
     
</ul>
</div>

        
</body>
</html>

Any ideas? I’ve tried everything I can think of as I said, so I’m just looking to see who has accomplished this with child or subcategories, not entries, which is the only thing I’ve found on any thread.

       
First 12 13 14 15 16 Last

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.