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
15 years ago
Laisvunas's avatar Laisvunas

Hi Gabriel,

In similar situations I use this code:

<li{if "{segment_2}" == "{child_category_url_title}"} class="current"{/if}>
       
Gabriel's avatar
Gabriel
130 posts
15 years ago
Gabriel's avatar Gabriel

@Laisvunas: thanks a lot. It’s working!

       
Tyssen's avatar
Tyssen
756 posts
15 years ago
Tyssen's avatar Tyssen

I know this question has probably been asked before and I’ve looked at a few examples/explanations but haven’t been able to get it working properly yet.

I want to display a list of subcategories nested within the parent’s list item but only when on either the page for the parent category or one of the child categories.

This is what I have so far:

{exp:weblog:categories weblog="services" sort="asc" style="linear" dynamic="off" parent_only="yes" show_empty="yes"}
    <li><a href="http://{path=detail/category}">{category_name}</a>
      {exp:child_categories parent="{category_id}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes"}
      
      {parent_category_start}
      parent_category_url_title
      {if "{parent_category_children_count}" > 0}<ul class="subnav">{/if}
      {parent_category_end}
      
      {child_category_start}<li><a href="http://{homepage}{segment_1}/detail/category/{child_category_url_title}/">{child_category_name}</a></li>{child_category_end}
      
      {parent_wrapper_bottom_start}
      </li>
      {if "{parent_category_children_count}" > 0}</ul>{/if}
      {parent_wrapper_bottom_end}
      {/exp:child_categories}     
      
      </li>
      {/exp:weblog:categories}
      </ul>

I know it’s probably going to involve {parent_category_url_title} or maybe another plugin in combination, but how do I only show the submenu under the conditions I mentioned above?

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

Hi Tyssen,

I want to display a list of subcategories nested within the parent’s list item but only when on either the page for the parent category or one of the child categories.

What you use to find that you are

1) on the page for the parent category;

2) on the page for the one of the child categories ?

       
Tyssen's avatar
Tyssen
756 posts
15 years ago
Tyssen's avatar Tyssen

When on the parent category page, I can use a URL segment, e.g. /template_group/detail/category/cat_url_title/ but the way things are currently, the subcategories have the same URL, so can’t use a segment to get the parent.

Or should I restructure the subcat URLs to look like /template_group/detail/parent_cat_url_title/category/child_cat_url_title/ ?

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

To reserve one URL segment for parent category url_title and another URL segment for child category url_title, perhaps would be easiest solution.

If you use only 2 levels of categories, then you can find if you are on parent’s page or on child’s page by using Category Id and Category Info pugins.

       
Tyssen's avatar
Tyssen
756 posts
15 years ago
Tyssen's avatar Tyssen

Not having much luck so far. If I do this, it’s printing out the ID of the currently viewed category, rather than doing any conditional filtering:

<ul class="sidenav">      
      {exp:weblog:categories weblog="services" sort="asc" style="linear" dynamic="off" parent_only="yes" show_empty="yes"}
    {if cat_status!="Closed"}<li><a href="http://{path={segment_1}/detail}">{category_name}</a>
      
      {exp:category_id category_group="8" category_url_title="{segment_4}"}
    {if category_id=="{category_id}"}
      
      {exp:child_categories parent="{category_id}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes"}
      
      {parent_category_start}
      {if "{parent_category_url_title}" == {segment_4}}
      <ul class="subnav">
      {/if}
      {parent_category_end}
      
      {child_category_start}<li><a href="http://{homepage}{segment_1}/detail/{if">{child_category_name}</a></li>{child_category_end}
      
      {parent_wrapper_bottom_start}
      </li>
      {if "{parent_category_url_title}" == {segment_4}}</ul>{/if}
      {parent_wrapper_bottom_end}
      {/exp:child_categories}     
      
      {/if}
      
      </li>
      {/if}
      {/exp:weblog:categories}
      </ul>

I haven’t gotten as far as working out what to do on subcategory pages.

       
jason-cpt's avatar
jason-cpt
8 posts
15 years ago
jason-cpt's avatar jason-cpt

Hi,

I’m having trouble running this excellent plugin on a Windows enviroment (IIS), I suspect it may have something to do with the Windows friendly URL, namely:

http://www.colorsfruit.com/QA/CMS/index.php?/the_colors_foundation/donors/

The error I am getting is:

Error The following tag has a syntax error: {exp:child_categories} Please correct the syntax in your template.

As it runs fine on a linux / apache server.

Here’s the template code used:

<li>
                <a href="http://index.php?/{segment_1}/purpose%22class=%22open_3" class="open_3">Purpose</a>
                <ul id="subSubNav3">
{exp:child_categories sibling="11" show_empty="yes" parse=“inward” status="open"}
{entries_start}
{if {child_category_id} == 11 && segment_2 == "purpose"}
                    <li><a href="http://index.php?/{parent_category_url_title}/{child_category_url_title}/{url_title}">{title}</a></li>
{/if}
{entries_end}
{/exp:child_categories}
                </ul>                
            </li>

I’m also using the pages module.

Any ideas on why is is happening?

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

Hi Tyssen,

In your template several things are wrong:

1) if you nest exp:child_categories inside exp:category_id, the you should add

parse="inward"

to exp:child_categories tag.

2) exp:category_id tag should have “weblog” parameter

3) {category_id} variable is parsed by both exp:category_id and exp:weblog:categories tag

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

Hi jason-cpt,

It seems that you could fix your conditional this way:

{if "{child_category_id}" == "11" && "{segment_2}" == "purpose"}
       
jason-cpt's avatar
jason-cpt
8 posts
15 years ago
jason-cpt's avatar jason-cpt

Sorry to waste eveyones time! The plug had not been installed by the tech - despite him saying otherwise! Should have checked “Utilties” > “Plugin Manager” instead of taking his word and rushing to the forums!

       
Tyssen's avatar
Tyssen
756 posts
15 years ago
Tyssen's avatar Tyssen
3) {category_id} variable is parsed by both exp:category_id and exp:weblog:categories tag

Yeah, I was wondering about that. So how do I go about matching the category and/or its parent against a URL segment? The code updated with the things you pointed out now looks like:

<ul class="sidenav">      
      {exp:weblog:categories weblog="services" sort="asc" style="linear" dynamic="off" parent_only="yes" show_empty="yes"}
    {if cat_status!="Closed"}<li><a href="http://{path={segment_1}/detail}">{category_name}</a>
      
      {exp:category_id category_group="8" weblog="services" category_url_title="{segment_4}"}
    {if "{category_id}"=="{category_id}"}
      
      {exp:child_categories parent="{category_id}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" parse="inward"}
      
      {parent_category_start}
      {if "{parent_category_url_title}" == {segment_4}}
      <ul class="subnav">
      {/if}
      {parent_category_end}
      
      {child_category_start}<li><a href="http://{homepage}{segment_1}/detail/{if">{child_category_name}</a></li>{child_category_end}
      
      {parent_wrapper_bottom_start}
      </li>
      {if "{parent_category_url_title}" == {segment_4}}</ul>{/if}
      {parent_wrapper_bottom_end}
      {/exp:child_categories}     
      
      {/if}
      
      </li>
      {/if}
      {/exp:weblog:categories}
      </ul>
       
Laisvunas's avatar
Laisvunas
879 posts
15 years ago
Laisvunas's avatar Laisvunas

Why do you need exp:weblog:categories tag?

If you want to display categories from the weblog “services”, then you can achieve it by using “category_group” parameter of exp:child_categories tag.

       
Tyssen's avatar
Tyssen
756 posts
15 years ago
Tyssen's avatar Tyssen
If you want to display categories from the weblog “services”, then you can achieve it by using “category_group” parameter of exp:child_categories tag.

I could if I could get my head around how this should work, but the more plugins I need to use, the less I’m getting what I should do.

Have you (or anyone else) got a basic example of how a two category level navigation that only shows the 2nd level when you’re on a page for that category’s parents or siblings should work? It’s for situations like these that I’d normally use the Structure module, but I don’t have that option in this case.

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

Try this code:

{exp:child_categories category_group="my_cat_group_id" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" parse="inward"}
      
      {parent_category_start}
      {parent_category_name}
      {parent_category_end}
      
      {child_category_start}
      {if "{parent_category_url_title}" == "{segment_4}"}
      {child_category_name}
      {/if}
      {child_category_end}

{/exp:child_categories}

This code will always display all parent categories of certain category group and will display subcategories of certain parent category in case url-title of that parent category is contained in the fourth URL segment.

       
First 16 17 18 19 20 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.