0

I am having difficulty understanding how to display multiple categories inside an entry. This example is for a church website where sermons have multiple categories, such as which service it was in, and who the speaker was.

This is what I'm trying to accomplish:

{exp:channel:entries channel="sermons" limit="10" orderby="entry_date" sort="asc"}
    <div class="post">
        <h3><a href="{title_permalink='sermons/'}">{title}</a></h3>
        <time>{entry_date format="%F %j, %Y"}</time>
        <span class="speaker">{speaker_name}</span>
        <span class="service">{service_name}</span>
    </div><!--/.post-->
{/exp:channel:entries}

As you can see, I want to display the two categories inside the entries loop, but I'm not sure how to do this.

Any guidance would be greatly appreciated. Thank you much!

1 Answer 1

0

You want to use the categories tag pair (not to be confused with exp:channel:categories)

{exp:channel:entries channel="sermons" limit="10" orderby="entry_date" sort="asc"}
    <div class="post">
        <h3><a href="{title_permalink='sermons/'}">{title}</a></h3>
        <time>{entry_date format="%F %j, %Y"}</time>
        {categories show_group="2"}
            <span class="speaker">{category_name}</span>
        {/categories}
        {categories show_group="3"}
            <span class="service">{category_name}</span>
        {/categories}
    </div><!--/.post-->
{/exp:channel:entries}

The above assumes that Speaker category group is ID 2 and Service category group is ID 3.

You could do it as one loop instead of the two:

    {categories show_group="2|3"}
        <span class="{if category_group == 2}speaker{if:elseif category_group == 3}service{/if}">{category_name}</span>
    {/categories}
1
  • That did it! Perfect and thorough explanation! I appreciate it immensely!
    – afferennen
    Mar 15, 2015 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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