ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Conditional Not Working

April 05, 2011 5:39pm

Subscribe [4]
  • #1 / Apr 05, 2011 5:39pm

    Geoff Towle

    330 posts

    Is there any reason why this conditional wouldn’t work?  I can only get the affirmative portion to work (Do A).  The conditional does not work for entries that are not category 15 or 17 (Do B).

    {exp:channel:entries limit="1" channel="items_of_interest" status="open|hidden"}
        {categories}
            {if category_id == "15" OR category_id == "17"}
                Do A   
            {if:else}
                Do B
            {/if}
        {/categories}
    {/exp:channel:entries}
  • #2 / Apr 06, 2011 12:16pm

    Lisa Wess

    20502 posts

    Hi, Geoff - that should work.  If you cut back to only testing for one category ID - does that work?  I just want to simplify it to see where it’s failing.

    Also, are the entries in more than one category? Say a parent and child?

    Thanks!

  • #3 / May 03, 2011 8:10pm

    Geoff Towle

    330 posts

    Hi Lisa,

    I think I maybe figured out why it is working the way it is, but I’m not sure how to fix it.  I think the way I wrote the condition, it assumed there are three categories, when in fact there are only two (15 and 17).  My assumption was that if:else would show anything in that channel that did not have a category.

    Does that sound like it could be the problem, and if so, any tips on a better way to achieve what I want?  Thanks.

  • #4 / May 04, 2011 7:02am

    John Henry Donovan

    12339 posts

    Geoff,

    it assumed there are three categories, when in fact there are only two (15 and 17).  My assumption was that if:else would show anything in that channel that did not have a category.

    Yeah that might be your issue. Your condition is inside the entries loop so will treat each entry it comes across with your condition which is not the gist of what you wanted to achieve I gather. You could always do something like this

    {exp:channel:entries limit="1" channel="items_of_interest" status="open|hidden" category="15|17"}
                Do A   
    {/exp:channel:entries}  
    
    {exp:channel:entries limit="1" channel="items_of_interest" status="open|hidden" category="not 15|17"}
                Do B
    {/exp:channel:entries}
  • #5 / May 04, 2011 12:20pm

    Geoff Towle

    330 posts

    John,

    Your solution works.  Thanks!

    Geoff

  • #6 / May 04, 2011 3:00pm

    Brandon Jones

    5500 posts

    Glad John Henry helped, Geoff!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases