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

Display div if this entry does not have a specific category

How Do I?

spunout's avatar
spunout
10 posts
10 years ago
spunout's avatar spunout

Hey there,

Sorry for what must be a fairly basic question. Our entries often have several categories assigned. I just want to be able to display a specific box if this entry does not have a certain category assigned to it.

{categories}
{if category_url_title != "some-category"} 
<div>THING TO BE DISPLAYED GOES HERE.</div>
{/if}
{/categories}

The above is what I want to do but it’s obviously wrong. As it will check each of the categories that the entry is assigned to and show the div each time the category doesn’t match.

Is there a way I can basically say show this code if the category “category-name” doesn’t match any of the categories assigned to this entry?

       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
10 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

I think the easiest solution for you might be an embed. In that template you’d have

{embed="site/check_for_category" entry_id="{entry_id}" cat_id="1"}

cat_id would be the ID of the category you want to check if the current entry is assigned to. Then your embedded template site/check_for_category would have the following code:

{exp:channel:entries entry_id="{embed:entry_id}" category="{embed:cat_id}" limit="1" dynamic="off" disable="member_fields|custom_fields|pagination"}
{if no_results}display this if not found{/if}
{/exp:channel:entries}
       

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.