0

Let's say I have entries tagged with multiples categories, for example category_id="1" and category_id="2".

Then when I do:

{exp:channel:entries channel="news" category="1" orderby="date" status="open"}
    {categories}
    <span>{category_id}</span>
    <h5><a href="{site_url}news/category/{category_url_title}/{url_title}">{title}</a></h5>
    {/categories}
{/exp:channel:entries}

I get the following result:

1
My entry title
2
My entry title
1
Another entry
2
Another entry

Why is that? How can I avoid this? If I ask specifically for category_id="1" in my {exp:channel:entries} parameter, I should get only entries belonging to said category.

Thanks in advance for your help.

FYI: EE version is v2.7.2

1 Answer 1

1

Looks like your code is a bit strange here, specifically the {categories}{/categories} tag pair wrapping everything.

Could you try the following and see if it works ?

{exp:channel:entries channel="news" category="1" orderby="date" status="open"}

    <h5>{title} - {categories}{category_id}{/categories}</h5>

{/exp:channel:entries}

If that works, then that's the problem.

Going back to your original code, I see another problem you are going to face if you structure your URLs like this: if an entry belongs to more than one category, you are going to have a problem constructing your URLs as you are doing here. If you can, working with url segments is probably a safer route here.

2
  • Thanks, it worked! You were right about the URL structure. As you suggested, I modified it using last_segment: <a href="{site_url}news/category/{last_segment}/{url_title}">{title}</a>
    – Macxim
    Mar 10, 2014 at 16:37
  • 1
    Yep, if you have your current category as last_segment, that would work IMHO Mar 10, 2014 at 16:38

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.