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.

showing the categories associated with a given entry?

February 02, 2011 2:44pm

Subscribe [3]
  • #1 / Feb 02, 2011 2:44pm

    roryrabbitfield

    320 posts

    I have a channel with various category groups. It is a multi-entry page. I would like, for each entry, to show what category/categories are assigned to each category group that exists for this channel.

    Here’s my EE channel tag and the code inside:

    {exp:channel:entries channel="classes" show_future_entries="yes" show_expired="no" sort="desc"}
    {title}
    
    {event_description}
    <span>Level:</span>
    
    <span>Audience:</span>
    
    <span>Format:</span>
    
    <span>Focus/Specialization:</span>
    
    {/exp:channel:entries}

    Level, audience, format, and focus are my 4 category groups. I want to show after those cat group names the actual categories that are assigned to each entry. How? Thanks.

  • #2 / Feb 02, 2011 3:23pm

    Leon Dijk

    131 posts

    Hi Rory,

    You should be able to do that easily with this plugin:
    http://devot-ee.com/add-ons/gwcode-categories/

    Your code would then look something like this:

    {exp:channel:entries channel="classes" show_future_entries="yes" show_expired="no" sort="desc"}
    {title}
    
    {event_description}
    {exp:gwcode_categories entry_id="{entry_id}"}
        {group_heading}<span>{group_name}</span>
    {/group_heading}
        {cat_name}
    {/exp:gwcode_categories}
    {/exp:channel:entries}

    This should work as well (linear list of categories instead of nested):

    {exp:channel:entries channel="classes" show_future_entries="yes" show_expired="no" sort="desc"}
    {title}
    
    {event_description}
    {exp:gwcode_categories entry_id="{entry_id}" style="linear"}
        {group_heading}
    <span>{group_name}</span>
    {/group_heading}
        {cat_name}
    
    {/exp:gwcode_categories}
    {/exp:channel:entries}

    Let me know if that helps!

    Cheers,
    Leon

  • #3 / Feb 02, 2011 4:00pm

    roryrabbitfield

    320 posts

    Looks interesting. I will check out this add-on. But before I do, I must ask, is there no way to do it without an add-on?

  • #4 / Feb 02, 2011 4:19pm

    Leon Dijk

    131 posts

    Not that I know of.
    You will get close with something like this:

    {exp:channel:entries channel="classes" show_future_entries="yes" show_expired="no" sort="desc"}
    {title}
    
    {event_description}
        {categories}
            {category_name}
        {/categories}
    {/exp:channel:entries}

    It will list all the categories, but I don’t think there’s a way to group them and show the category group name, there’s no {group_name} variable or something like that:

    http://ellislab.com/expressionengine/user-guide/modules/channel/variable_pairs.html#var_categories

    Cheers,
    Leon

  • #5 / Feb 02, 2011 5:31pm

    roryrabbitfield

    320 posts

    I see what you mean. I think I’ll try the add-on! Thanks for the help.

  • #6 / Feb 02, 2011 5:38pm

    Ingmar

    29245 posts

    Thanks for stepping in 😊 Please post again in case there’s anything else.

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

ExpressionEngine News!

#eecms, #events, #releases