2

I have this markup:

{exp:channel:entries channel="imagegallery"}
<div class="element {exp:channel:categories category_group="1" channel="imagegallery" style="linear"}{category_url_title}{/exp:channel:categories}">
    <p>Bla Bla</p>
</div> 
{/exp:channel:entries}

I'd like to add the current category as a class. With this markup all categories are added. But I only want the one from this channel entry. How do I do this?

Thank you

8

The {exp:channel:categories} tag is specifically for displaying a list of all categories. You can use the {categories} variable pair inside of the {exp:channel:entries} loop to get the assigned categories to that entry. You can read more at the docs

{exp:channel:entries channel="imagegallery"}
<div class="element {categories backspace="1"}{category_url_title} {/categories}">
    <p>Bla Bla</p>
</div> 
{/exp:channel:entries}
2
  • Thank you. What is backspace="1" for?
    – KSPR
    Jan 9 '13 at 10:26
  • The backspace parameter removes characters & line breaks at the end of the last iteration in the loop. So I have set it to 1 to remove that space.
    – Siebird
    Jan 9 '13 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.