We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Help with categories

How Do I?

Crnaovca's avatar
Crnaovca
627 posts
10 years ago
Crnaovca's avatar Crnaovca

In channel entries tag I have something like this

{if category =="39|50|51"} do this {if:else} do that {/if}

if statement is not working. I do not get it why. there are no variables for channel entries so I presume that is part of the problem. But how to do it then? How to check if entry has category to display one message, if it has another display something else

{exp:channel:entries channel="katalog" limit="12" dynamic="yes" status="open" show_future_entries="no" orderby="date" sort="desc" disable="member_data" pagination="bottom"}

{if category =="39|50|51"}

{exp:channel_images:images entry_id="{entry_id}" channel="katalog" limit="1" cover_only="yes"}
show image

{if image:no_images}
show alternative image that says NO IMAGE found
{/if}
{/exp:channel_images:images}

{if:else}
show something completely else for entries that are not in category 39, 50 or 51
{/if}

{/exp:channel:entries}
       
USC Chan's avatar
USC Chan
81 posts
10 years ago
USC Chan's avatar USC Chan

I don’t think this code:

{if category =="39|50|51"}

works the way you expect. Try separating the conditions:

{if category == "39" OR category == "50" OR category == "51"}
       
Crnaovca's avatar
Crnaovca
627 posts
10 years ago
Crnaovca's avatar Crnaovca

But that is same thing …

       
EB's avatar
EB
12 posts
10 years ago
EB's avatar EB

Did you get this resolved? In order to call categories to use in a conditional, you need to use the categories looping pair. https://ellislab.com/expressionengine/user-guide/add-ons/channel/channel_entries.html#categories. Then you need to use the {category_id} in your conditional.

You can guess though that doing things this way might be tricky with the conditional logic you’re currently using. Since a post can have multiple categories the contents of the conditional would be output once per match with a category…

       
Crnaovca's avatar
Crnaovca
627 posts
10 years ago
Crnaovca's avatar Crnaovca

Yes, but if I use category pair, and entry has 3 categories at same time, it will be displayed 3 times right?

       
EB's avatar
EB
12 posts
10 years ago
EB's avatar EB

I’m not sure categories is the best way to approach the functionality you’re trying to provide. You’d be calling three nested loops (the entries, then the categories, then the dev-demon channel images), which it seems to me isn’t very efficient to grab one image.

Why not create another custom field for “post_featured_image” and use a conditional like {if post_featured_image} instead? I know that’s not the answer you were looking for, but it would certainly be more efficient!

Are other categories going to have channel-images associated with them?

       
Crnaovca's avatar
Crnaovca
627 posts
10 years ago
Crnaovca's avatar Crnaovca

Thank you but I know it can be solved using categories, and in this situation, using categories is the best thing except in this situation. To change everything because of one situation is not reasonable.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.