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.

Question about {category} loops

October 18, 2012 11:45am

Subscribe [2]
  • #1 / Oct 18, 2012 11:45am

    e-finity

    22 posts

    Hello,

    We’ve setup a blog within our site where posts belong to one or many of a series of categories.

    We want to display different icons within the post depending on the categories the post belongs to.

    Using the {categories} tag I’m able to output the categories a post is assigned to but I can’t work out how to loop through these categories in order to display the icons.

    In traditional PHP I’d hold the categories in an array and use a loop to output the corresponding icons, e.g. category 1, 4 & 5, so display icon 1, 4 & 5.

    Can someone point me in the right direction on how I might achieve similar using EE syntax?

    Thanks.

  • #2 / Oct 19, 2012 10:17am

    Boyink!

    5011 posts

    Maybe I’m missing it but why not just:

    {exp:channel:entries channel="foo"}
    {categories}
     {caetgory_name} {category_image} 
    {/categories}
    {/exp:channel:entries}

    I forget offhand if the image variable returns image markup but you’ll figure that out soon enough…

  • #3 / Oct 22, 2012 9:22am

    Dan Decker

    7338 posts

    Hi e-finity,

    Mike offers one easy approach, using the built-in category image field. Thanks Mike!

    That’s the most straightforward way to handle this and keeps everything in the Control Panel’s category management screens.

    Let me know if you have any questions!

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases