0

Is there a way to say "If this entry contains category 5" rather than "If this entry's category is category 5"?

Consider this:

{categories}
{if category_id="5"}
Do something
{/if}
{/categories}

I believe the condition would only return true of the only category assigned is category 5. If an entry has categories 5 and 6 assigned, it would not be returned here, but that's what I'm looking for.

Possible?

1

If u want to only DO Something for the entries belong to category(id=5) your code will do the trick but if u use "show" param the code will be better:

{categories show="5"}
Do something
{/categories} 

but If u want to Do Something for the entries belong to category(id=5) and another Thing for the entries don't belong to category(id=5) try to use:

{categories show="5"}
Do something
{/categories} 
{categories show="not 5"}
Do Another thing
{/categories} 

I hope this will do the trick.

Regard's.

2
  • But isn't the value of the category for an entry with categories 5 and 6 assigned to it "56" and therefore not 5? – Mike Mella Mar 14 '14 at 19:09
  • No , we you assigned entry to category this will add a new row to exp_category_posts(entry_id,cat_id) columns, category values is a multi row values so EE use it as a tag pair. – Ahmad Saad Mar 14 '14 at 19:41
0

If I'm not mistaken your code should do exactly that.

It would find 5 in the loop and 'do something' and then loop again at 6 and do nothing because there's nothing to execute.

May not be especially efficient but should work.

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.