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

Bjørn Børresen's avatar
Bjørn Børresen
629 posts
16 years ago
Bjørn Børresen's avatar Bjørn Børresen

Is there a way to get this to list all categories (recursively) .. or does it just go one level down?

I’m looking for a solution to output a structure like this:

Category 1 - SubCat 1 - SubSubCat 1 - SubSubCat 2 - SubSubSubCat 1 Category 2 - SubCat 2 - SubSubCat 2 - SubSubCat 3

..etc.

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

Hi Bjorn,

The aim of this plugin to display child categories one level down, although by using this plugin together with some other plugin or EE tag it is possible to display additional levels of categories.

T o display all categories whatever deep they are in categories tree it seems best to use exp://weblog:category_archive tag.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

I’d like to output a comma-delimited list of my sub-categories. Within the {child_category_start}{child_category_end} tags, what is the easiest way to make sure that the comma does not get output after the last category?

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

Hi Ryan,

It seems to me that the easiest way to achieve it would be to to wrap the output of {child_category_start}{child_category_end} variable pair with the tags of Find and Replace Plus or Find and Replace plugin; plugin’s tag would have parameters regex=”yes” and find=”your_regex_string”.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

I’ll try that suggestion. My only problem will be the RegExp to find the last comma and SPACE only, rather than all of them.

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

Hi Ryan,

It seems that there is a simpler solution to your problem: you can use PHPStringFun plugin.

Using this plugin you can wrap the output of {child_category_start}{child_category_end} variable pair with its tags and use PHP rtrim function:

{exp:phpstringfun function="rtrim" par1=","}{child_category_start}{child_category_name},{child_category_end}{/exp:phpstringfun}
       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

Absolutely nothing seems to be working for this. I’ve tried PHPStringFun, resorted to enabling PHP on the template and using PHP rtrim - I’m just always seeing the comma after the last item.

I’m looking inside the plugin to see how it is constructed to ee if I figure out why trying to do something with the resulting output isn’t working for me.

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

Hi Ryan,

For some reason the code as this does not work:

{exp:child_categories parent="179" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="no" site="1" parse="inward" status="open|closed"}
{exp:phpstringfun function="rtrim" par1=","}{child_category_start} {child_category_name},{child_category_end}{/exp:phpstringfun}
{/exp:child_categories}

But the code as this works correctly:

{exp:phpstringfun function="rtrim" par1=","}{exp:child_categories parent="179" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="no" site="1" parse="inward" status="open|closed"}{child_category_start} {child_category_name},{child_category_end}{/exp:child_categories}{/exp:phpstringfun}
       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

Thank you for looking into that. I ended up getting this to work with some much simpler CSS (not IE6 friendly, but IE6 users should just see a spaced list of items with no commas, so no real harm there). Here is the CSS:

ul.subclass-list li:after { content:', '; }
ul.subclass-list li:last-child:after { display:inline; content:''; }

That puts a comma after every item in the list except the last one.

       
bene's avatar
bene
20 posts
16 years ago
bene's avatar bene

Hello,

how can I use a custom category field, I need it between the child_category_start and _end tags

{child_category_start}

    {if user_language=="nl"}
        {child_category_name}
    {if:else}
        {child_category_name_{user_language}}
    {/if}
{child_category_end}

Thanks for your reply, Tim

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

Hi Tim,

Since Child Categories plugin cannot output contents of custom category fields, you should use this plugin together with som other EE tag, such as exp:weblog:category_archive or exp:weblog:categories. If you use Child Categories plugin together with some of these tags, don’t forget to add

parse="inward"

parameter to exp:child_categories tag!

Unfortunately, these EE tags require parameter “weblog” to be defined.

If you can specify exactly one weblog, then your code could be somethind like this:

{child_category_start}

{exp:weblog:category_archive weblog="my_weblog" show="{child_category_id}" style="linear"}

{categories}

    {if user_language=="nl"}
        {child_category_name}
    {if:else}
        {child_category_name}_{user_language}
    {/if}

{/categories}

{/exp:weblog:category_archive}

{child_category_end}
       
Asite's avatar
Asite
15 posts
16 years ago
Asite's avatar Asite

Hello,

I want Category name and Entries in a collapsible menu, There is no subcategories. For Example

Category 1 - Entry 1 - Entry 2 Category 2 - Entry 3 - Entry 4

My code using this plugin is as below.

{exp:weblog:categories category_group="3" weblog="weblog_name" dynamic="off" style="linear"} {exp:child_categories parent="{category_id}” child_categories_sort_by=”custom” child_categories_sort_direction=”asc” show_empty=”no” entries_sort_by=”date” entries_sort_direction=”asc” entries_limit=”5” site=”1”} {parent_category_start} {parent_category_name} {parent_category_end} {entries_start} {title} {entries_end} {/exp:child_categories} {/exp:weblog:categories}

It shows categories but does not show entries.

Do I forget to add something in code?

Thanks

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

Hi Asite,

Child Categories plugin does not display entries if there are no subcategories. To display entries posted into certain categories you should use exp://weblog:category_archive tag.

       
florian's avatar
florian
395 posts
16 years ago
florian's avatar florian

For this project I have categories, subcategories and products. I am displaying the categories on 1 template (index) and the subcategory on another template (list), and the products belonging to that subcategory on another template (prod-list) and a detailed description of the product on another template called (detail). All templates are in the same template group (products).

1 Weblog called “products” 1 Category Group assigned to Weblog “prodcuts” with following structure:

LEVEL1 Fruit LEVEL2 Apricot LEVEL2 Cherry LEVEL2 Citrus

LEVEL1 Vegetables LEVEL2 Beans LEVEL2 Beets LEVEL2 Carrots

I template group (products) with the following templates: index list product-list detail

I use 2 plugins: child categories and category id

The index template displays the 2 LEVEL1 categories: Fruit and Vegetables

{exp:weblog:categories weblog="products" parent_only="yes" style="linear"} <li class=”left-img left-img-2”>{category_image}{category_name}</li> {/exp:weblog:categories}

When I click on the fruit or vegetable link in the index template I link to “list” template and display the LEVEL2 sub-categories: Apricot, Cherry, Citrus. I am using the category ID plugin to call my category name from segment_4 and convert it into an ID for the category_id. This works fine.

{if segment_4!=""} {exp:category_id category_group="3" category_url_title="{segment_4}” parse=”inward”} {exp:child_categories parent="{category_id}” child_categories_sort_direction=”asc” show_empty=”yes” entries_sort_direction=”asc” parse=”inward”} {child_category_start} <li class=”left-img left-img-2”>{child_category_name} _title={child_category_name}</li> {child_category_end} {/exp:child_categories} {/exp:category_id} {/if}

When I click on one of the sub-categories from the “list” template, I link to another template called “product-list” which should display all the products assigned to this sub-category. At this point I am stuck. I tried to pass the {parent_category_id} and {child_category_id} into the url and again grab it from the segment. However, this approach doesnt seem to work.

{if segment_3!=""} {exp:category_id category_group="3" category_url_title="{segment_3}” parse=”inward”} {exp:child_categories parent="{category_id}” child_categories_sort_direction=”asc” show_empty=”yes” entries_sort_direction=”asc” parse=”inward”} {child_category_start} <li class=”left-img left-img-2”>{child_category_name} _title={child_category_name}</li> {child_category_end} {/exp:child_categories} {/exp:category_id} {/if}

My last step will be to display a detailed prodcut description. This will link to the “detail” template.

I am not sure if I am going about this the correct way. Is there a mistake in my code or should I structure/rethink my approach? I would appreciate some pointers.

thank you very much,

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas
{if segment_4!=""} {exp:category_id category_group="3" category_url_title="{segment_4}” parse=”inward”} {exp:child_categories parent="{category_id}” child_categories_sort_direction=”asc” show_empty=”yes” entries_sort_direction=”asc” parse=”inward”} {child_category_start} <li class=”left-img left-img-2”>{child_category_name} _title={child_category_name}</li> {child_category_end} {/exp:child_categories} {/exp:category_id} {/if}
When I click on one of the sub-categories from the “list” template, I link to another template called “product-list” which should display all the products assigned to this sub-category. At this point I am stuck. I tried to pass the {parent_category_id} and {child_category_id} into the url and again grab it from the segment. However, this approach doesnt seem to work.

If I understood you correctly, you pass child_category_url_title from template “list” to template “prod-list” as the fourth url segment. Now, if you need child_category_id, use category_id plugin, as in template “list”:

{if segment_4!=""}
{exp:category_id category_group="3" category_url_title="{segment_4}" parse="inward"}
{category_id}
{/exp:category_id}
{/if}
       
First 7 8 9 10 11 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.