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.

Category Help

September 02, 2011 1:40am

Subscribe [2]
  • #1 / Sep 02, 2011 1:40am

    Dazeone

    6 posts

    Hi,

    I am new to EE and I am trying to wrap my brain around how categories work in EE. I am chunking up a basic HTML template and trying to create a navigation bar using an unordered list and have EE display this list of the categories that I have in a particular category group.

    I have created a category group called “content” which has the categories “tech”, “cars”, “sports”, etc. I have channels such as “articles”, “pictures”, etc. What I’m looking for would be something like this:

    <ul>
    <li><a href="/tech">Tech</a>
        <ul><li>Articles</li>
            <li>pictures</li>
            <li>etc…</li>
        </ul></li>
    <li><a href="/cars">Cars</a>
        <ul><li>Guides</li>
            <li>Pictures</li>
            <li>etc…</li>
        </ul></li>
    </ul>

    So my question is whether I am misunderstanding how categories work in EE and if not, how do I use tags to create this sort of structure and secondly. The user guide seems to suggest that displaying categories is related to a specific channel? Any help is much appreciated!

  • #2 / Sep 02, 2011 8:48am

    Rob Allen

    3114 posts

    You need the Channel categories tag - http://ellislab.com/expressionengine/user-guide/modules/channel/categories.html

    The basic syntax for outputting a list of categories in nested UL’s is this:

    {exp:channel:categories}
    <a href="http://{path=template_group/index}">{category_name}</a>
    {/exp:channel:categories}

    You may need to add some parameters to the tag to get it working how you need it, eg adding a class name, but see the Docs for availabel options.

  • #3 / Sep 02, 2011 10:41pm

    Dazeone

    6 posts

    I have been trying to use that tag.  Correct me if I’m wrong but it needs a channel name as a parameter. This seems backwards to me as not all categories will have all channels (ie. I might have a pictures channel for the “cars” category but not for the “tech” category.).

  • #4 / Sep 04, 2011 1:52pm

    Rob Allen

    3114 posts

    Yes you’d most likley need a Channel parameter (but not always depending what you’re trying to do)

    You can output the same category tag twice, split by Channel, eg

    {exp:channel:categories channel="articles"}
    <a href="http://{path=template_group/index}">{category_name}</a>
    {/exp:channel:categories}  
    
    {exp:channel:categories channel="pictures"}
    <a href="http://{path=template_group/index}">{category_name}</a>
    {/exp:channel:categories}

    Or you could combine the categories tag to cover all Channels, eg

    {exp:channel:categories channel="articles|pictures"}
    <a href="http://{path=template_group/index}">{category_name}</a>
    {/exp:channel:categories}

    Does that help?

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

ExpressionEngine News!

#eecms, #events, #releases