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.

Channel Categories: how to get different markup for parent/child categories?

October 09, 2010 8:33pm

Subscribe [4]
  • #1 / Oct 09, 2010 8:33pm

    imolta

    11 posts

    I’m using {exp:channel:categories} to display a navigation menu with four parent categories, each with a number of child categories. I can’t seem to figure out how to get different markup for each. There doesn’t seem to be a reference for conditionals that will work within this tag.

    Current code:

    {exp:channel:categories channel="default_site" style="nested"}
    <a href="http://{path=site/overview}">{category_name}</a>
    {/exp:channel:categories}

    What I’d like is for the parent categories to use the template ‘site/overview’ and the children to use a different template, e.g. ‘site/category’. What do I need to do to accomplish this?

    I’d also like to be able to selectively append classes, e.g. to style the last item in the outputted list differently.

  • #2 / Oct 10, 2010 3:56pm

    Greg Salt

    3988 posts

    Hi imolta,

    You have to build the list structure yourself if you use the linear style instead of the nested one and that might give you a little bit more flexibility. However, something like this should get you on your way:

    {exp:channel:categories channel="default_site" style="nested"}
    {if parent_id == 0}
        <a href="http://{path=site/overview}class=last_item">{category_name}</a>
    {/if}
    {if parent_id > 0}
        <a href="http://{path=site/category}class=last_item">{category_name}</a>
    {/if}
    {/exp:channel:categories}

    Cheers

    Greg

  • #3 / Oct 12, 2010 4:23pm

    imolta

    11 posts

    Thanks for the help, Greg - that is indeed enough to get me started!

  • #4 / Oct 13, 2010 9:14am

    Sue Crocker

    26054 posts

    Glad Greg was able to help. Don’t hesitate to post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases