1

this code has worked great for a long time. I pull entries and use an IF statement around which category they are in:

{exp:channel:entries channel="resources" dynamic="on" limit="1"}

    {if "{categories}{category_id}{/categories}” == “44” OR “{categories}{category_id}{/categories}” == “191” } 
    ....
    {/if}

    {if "{categories}{category_id}{/categories}” == “45”}
      ....
    {/if}

All was good until I got an entry with more than one category (84 & 191). The output is {category_id} = “84191” which doesn't get caught in my conditional.

I don’t want to use the “contains” conditional b/c then an entry with category 84 & 4 would be “844” and would match me looking for category=44. How do I solve this??

Thanks!

1

To prevent your issue with 84 & 4 occurring, you could use code like this, where you surround the category IDs with something to make them separate:

{exp:channel:entries channel="resources" dynamic="on" limit="1"}

    {if "{categories}({category_id}){/categories}" *= "(44)" OR "{categories}({category_id}){/categories}" == "191" } 
    ....
    {/if}

    {if "{categories}({category_id}){/categories}" *= "(45)"}
    ....
    {/if}

Depending on your use case, it might be better written as

{exp:channel:entries channel="resources" dynamic="on" limit="1"}
    {categories}
        {if "{category_id}" == "44" OR "{category_id}" == "191" }
        ....
        {/if}

        {if "{category_id}" == "45"}
        ....
        {/if}
    {/categories}

Though then you'd get output twice if your entry was in both categories 44 and 191.

| improve this answer | |
  • adding the parenthesis works great! thanks – lelkins001 Mar 5 '15 at 19:07

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.