ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Categories - getting only children of a given parent

December 09, 2010 8:21am

Subscribe [5]
  • #1 / Dec 09, 2010 8:21am

    Mitch Cohen

    12 posts

    I have a channel with a set of categories, each with a few subcategories.  I have this code (simplified):

    {exp:channel:categories channel="theChannel"}
    <input type="checkbox" value="something" /> {category_name}
    {/exp:channel:categories}

    I want to show only the children of a specific parent.  Let’s say the a parent is category 1 and its children are 2, 3, and 4.

    If I add:

    show="1"

    I get only the parent.

    If I add:

    show="1|2"

    I get the parent and the first child.

    But if I add:

    show="2"
    (or
    2|3|4

    )

    I get nothing, likely because the parent isn’t included.

    My only thought thus far is to use

    style="linear"

    and force-hide the first item.  This seems messy.

    Any suggestions?  Thanks!

  • #2 / Dec 09, 2010 3:12pm

    Neil Evans

    1403 posts

    i am hitting exactly the same wall - its painful. I have tried using LOW’s seg2cat which gives you a few more variables to do logic with, but this is only as good as id and parent id - which does not help me at all as i have more than 1 level of categories. Same applie to the child_categories plugin - although this one might work for you.

    if you have worked anything out i would be interested to know what.
    At the moment i am looking to battle with my own plugin just to produce as simple menu from categories - basic stuff which EE is really not helping me with… annoying.

  • #3 / Dec 09, 2010 3:26pm

    Try this,

    {exp:channel:categories channel="theChannel" category_group="1"}
    <input type="checkbox" value="something" /> {if parent_id !="0"}{category_name}{/if}
    {/exp:channel:categories}

    Hope this helps.

    Regards,

    Bashir Tahir

    ——Edit———
    This will not, perhaps, work with multilevels.

  • #4 / Dec 09, 2010 3:39pm

    Neil Evans

    1403 posts

    Hi Cheers, see what you have done, but for me it will not work as trying to display a three tiered menu, with multiple items beneath each… hence the above would not isolate it to each individual active parent… i’ll keep pluging away, but thanks.

  • #5 / Dec 10, 2010 9:54am

    Ingmar

    29245 posts

    Does that help, Mitch? Unfortunately I am not aware of a better option to show children only, i.e. without their parents. Might make for a good Feature Request, I think.

  • #6 / Dec 10, 2010 10:14am

    Neil Evans

    1403 posts

    i am building a plugin - will send it when done. a feature request will take years to come out.

  • #7 / Dec 10, 2010 12:02pm

    Mitch Cohen

    12 posts

    I thought of that too.  In this limited case it should do the trick, as once developed this site’s categories (and parents) shouldn’t change so hard-coding them is at least functional.  It would be nice to have a more automated approach.

    Does that help, Mitch? Unfortunately I am not aware of a better option to show children only, i.e. without their parents. Might make for a good Feature Request, I think.

  • #8 / Dec 10, 2010 5:55pm

    Sue Crocker

    26054 posts

    Hi, Mitch. Please do consider leaving a feature request, and have it be a “story” about why you want or need a particular feature.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases