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

OutofControl's avatar
OutofControl
164 posts
15 years ago
OutofControl's avatar OutofControl

Okay, got part of it. I need to embed the child_category_id like so:

{if {child_category_id} == '53'}

Now, I wonder if there is any way to accomplish

{if {child_category_id} == '50|51|52|53'}
       
Laisvunas's avatar
Laisvunas
879 posts
15 years ago
Laisvunas's avatar Laisvunas

Hi,

Your code should be:

{if "{child_category_id}"=="50" OR "{child_category_id}"=="51" OR "{child_category_id}"=="52" OR "{child_category_id}"=="53"} 
Some code
{/if}
       
LucPestille's avatar
LucPestille
146 posts
15 years ago
LucPestille's avatar LucPestille

I’ve got two parent category groups, and I’m trying to re-create this bit of code to show the one (or more) categories that have been selected for an entry:

{categories backspace="1" show="not 17|18|19|20|21|22|77|78|79|80|81|82|83|84|85"}{category_name}, {/categories}

with the child categories plugin:

{exp:child_categories parent="17"}
{child_category_start}{child_category_name}, {child_category_end}
{/exp:child_categories}

But instead of just getting one category out, I get all the child categories shown. Have I got the wrong end of the stick somewhere?

Thanks,

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

Hi Luc,

Your code should be as this:

{exp:child_categories parent="17"}
{child_category_start}

{if "{child_category_id}" != "17" AND "{child_category_id}" != "18" AND "{child_category_id}" != "19"}
{child_category_name},
{/if} 

{child_category_end}
{/exp:child_categories}
       
Steve Abraham's avatar
Steve Abraham
149 posts
15 years ago
Steve Abraham's avatar Steve Abraham

A quick suggestion (unless there’s another way round it):

{child_category_children_count}

I want to list out all child categories from a given parent, but I want to make the child categories a link only if they have child categories themselves…

  • Parent 1 —Child 1 (not a link because {child_category_children_count} == 0) —Child 2 (link because {child_category_children_count} == 2) ——Child 2’s Child 1 ——Child 2’s Child 2 —Child 3 (not a link because {child_category_children_count} == 0)
       
Laisvunas's avatar
Laisvunas
879 posts
15 years ago
Laisvunas's avatar Laisvunas

Hi Steve,

Child categories plugin is meant only to output categories 1 level deep, i.e. parent categories and their children, not childrens’ children.

If you want to display categories more than 1 level deep you might find the plugin Recursive Subcategories useful.

       
Steve Abraham's avatar
Steve Abraham
149 posts
15 years ago
Steve Abraham's avatar Steve Abraham

Hi - thanks for a quick response.

Understood re: displaying more than one level, however I’m actually only wanting to display parent and child, the problem is I want to make the child clickable ONLY if it has children itself (I don’t want to actually display the child’s children).

I’ll try the recursive subcategories plugin, but I found your one perfect (since I can display entries too with the same code).

Thanks! Steve.

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

If you don’t want to display childrens’ Children, then it it possible to achieve what you need:

{if "{child_category_children_count}"=="0"}
Code without link
{/if}
{if "{child_category_children_count}">"0"}
Code with link
{/if}
       
Steve Abraham's avatar
Steve Abraham
149 posts
15 years ago
Steve Abraham's avatar Steve Abraham

Oh - does {child_category_children_count} exist? Oops, that’s what I was suggesting, I didn’t see it in the documentation.

       
Laisvunas's avatar
Laisvunas
879 posts
15 years ago
Laisvunas's avatar Laisvunas
Oh - does {child_category_children_count} exist?

Opps! - I assumed you are talking about existing variable…

       
Steve Abraham's avatar
Steve Abraham
149 posts
15 years ago
Steve Abraham's avatar Steve Abraham

Sorry - no, I was making a suggestion/feature request. :D

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

You can use Child categories plugin together with Category Info plugin.

       
LucPestille's avatar
LucPestille
146 posts
15 years ago
LucPestille's avatar LucPestille
Hi Luc, Your code should be as this:
{exp:child_categories parent="17"}
{child_category_start}

{if "{child_category_id}" != "17" AND "{child_category_id}" != "18" AND "{child_category_id}" != "19"}
{child_category_name},
{/if} 

{child_category_end}
{/exp:child_categories}

Hi, That just outputted the same as I had - every child category, regardless of it being selected. I should have probably said that category_id 17 and 18 are the parents, all the rest are children.

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

Hi Luc,

That just outputted the same as I had - every child category, regardless of it being selected. I should have probably said that category_id 17 and 18 are the parents, all the rest are children.

I don’t understand which one category you want to output. How do you distinguish selected category from others? And what do you mean by “selected category”?

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

What I mean, and what I get from my code (although I have to manually enter category IDs when they’re added to, hence the use of this plugin), is a list of child categories that have been selected for that particular entry. For example, I have categories set up like

17 - Parent 1 —- Child 1 —- Child 2 —- Child 3

18 - Parent 2 —- Child 4 —- Child 5 —- Child 6

Selecting “Child 2” in the publish/edit screen should then only output “Child 2” in my template.

Hope that’s clearer…

       
First 18 19 20 21 22 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.