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

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

That is correct. From template “list”, I pass {parent_category_url_title} as segment 3 and {chilc_category_url_title} as segment 4 to the templatel “prod-list”.

I updated the code for the “prod-list” template today and made some progress. In my previous code, I forgot to include the {entries} tag which is needed to display the entires for the subcategory. here is the current code:

{exp:category_id category_group="3" category_url_title="{segment_4}" parse="inward" }
{exp:child_categories weblog="products" parent="{category_id}" parse="inward" }
{entries_start}
                                    <li class="left-img left-img-2"><a href="http://{path=products/details}">{product_thumbnail}{title}</a></li>
{entries_end}
{/exp:child_categories}
{/exp:category_id}

The problem that I am having is that the entries dont display correctly. My theory is that it may not be possible to take segment 4 (which is child category url title) and use that as the {category-id} for the parent tag on the prod-list template?

the url structure on list is: http://www.site.com/index.php/products/list/category/fruit/

the url structure on prod-list is: http://www.site.com/index.php/products/prod-list/fruit/apricot/

when I try to use segment4 as my category_id, nothing displays. when I try to use segment3 all entries display from all subcategories, which makes sense because segment3 would be the main parent category. Is there a solution?

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

Hi Florian,

Correct if I’m wrong:

1) “Fruit” is level 1 category

2) “Apricot” is level 2 category

3) there are some entries posted into category “Apricot”

4) you need to display those entries using URL http://www.site.com/index.php/products/prod-list/fruit/apricot/

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

1.) this is correct. Fruit is the level 1 category which holds a few subcategory, including: 2.) apricot is one of the level 2 categories. 3.) there are some weblog entries in the category apricot. 4.) I am not sure if I have to display them using the url http://www.site.com/index.php/products/prod-list/fruit/apricot/ This was the best solution that I was able to come up with that would let me display the entries of a certain category on the “prod-list” template. I passed the parent_category_url_title and child_category_url_title to the “prod-list” template when I link from the “list” template to a subcategory.

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

Yet another question: do you include “fruit” as the third URL segment because you want to display some info about level 1 category or just in order to have pretty URL?

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

on my “list” template, segment3, fruit gets displayed because I link to it with the category tag. So I think ee automatically puts segment2 “category”, and segment3 “fruit” in the url. When I link from “list” to “prod-list” template, I am passing parent_category_url_title which is segment3 or fruit, and I pass child_category_url_title which is segment4 or apricot. The reason I try it this way was because I thought that I needed to have that info in the url on the “prod-list” template so that I could read the category_id number and then display the entries for sub category apricot. Is this approach where the problem is? So the reason is not for pretty url or anything, I am just trying to get it to work.

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

Hi Florian,

If you do not need to output any info about level 1 category, then you can simply use exp:weblog:entries tag; there is no need to use Child Categories plugin:

{exp:category_id category_group="3" category_url_title="{segment_4}" parse="inward" }
{exp:weblog:entries weblog="products" category="{category_id}"}
<a href="http://{path=products/details}{url_title}">{title}</a>

{/exp:weblog:entries}
{/exp:category_id}
       
florian's avatar
florian
395 posts
16 years ago
florian's avatar florian

That worked for me. Thank you so much for your help.

       
brittanyA's avatar
brittanyA
184 posts
16 years ago
brittanyA's avatar brittanyA

Is there a conditional that might work this way: {if:this category has child categories} –content– {/if} ?

Thanks!

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

Hi brittanyA,

Yes, you can achieve this by writing the code as this:

{exp:child_categories parent="18|29" child_categories_sort_by="custom" child_categories_sort_direction="asc" site="1"}

{parent_category_start}

{if "{parent_category_children_count}" > 0}

Some code

{/if}
  
{parent_category_end}


{/exp:child_categories}
       
Kev-O's avatar
Kev-O
50 posts
16 years ago
Kev-O's avatar Kev-O

Laisvunas, love your plugin it’s saved me SO much time.
I am however running into a problem that I’m hoping there is a simple answer to. I want to show a list of 3 random child categories from one parent. Is this somehow possible? I’ve read over the documentation and I can’t seem to find anything that will allow me to do that. Any advice would be appreciated.

Thanks,

-kev

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

Hi Kev,

What you need is in principle achievable.

Two things are missing:

1) plugin which would expose PHP rand() function through EE tag;

2) Child Categories plugin variable {child_category_count} which would output count number of the child category.

Both would be good to have. I will try to implement these things in forthcomming days.

       
Kev-O's avatar
Kev-O
50 posts
16 years ago
Kev-O's avatar Kev-O

I’d thought about going in and tweaking your plug-in for that added random functionality, but it looked like a more difficult endeavor than I had originally thought. That would be a great addition to an already very useful plug-in, thanks for getting back to me so quickly.

-kev

       
michelG's avatar
michelG
32 posts
16 years ago
michelG's avatar michelG

Hi Laisvunas.

Would you have any comments or resolution regarding my earlier note quoted below? Since then, I have installed your latest 1.5.1 version but the problem is still the same.

- Category custom field: Hmmm… In the following code, the value of the category custom field ({sitemap_template}) that is retrieved is the one of the parent, not the one of the child. I use it in the child’s URL to define what template should be used.
<ul>
{exp:weblog:entries weblog="{my_weblog}"}
{categories}
{exp:child_categories parent="{category_id}" child_categories_sort_by="custom" show_empty="yes"}
{child_category_start}
<li><a href="/index.php/{sitemap_template}/c/{child_category_url_title}">{child_category_name}</a>
{if "{child_category_description}"}
{child_category_description}{/if}</li>
{child_category_end}
{/exp:child_categories}
{/categories}
{/exp:weblog:entries}
</ul>
       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi Michel,

I do not understand, what is here a problem for you.

Is it that {sitemap_template} variable displays the value of custom field of the parent category, but you need to display the value of custom field of child category?

       
michelG's avatar
michelG
32 posts
16 years ago
michelG's avatar michelG

You understand me correctly, Laisvunas.

       
First 8 9 10 11 12 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.