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.

Use If Statement for Entries Based Upon Category

May 05, 2011 3:29pm

Subscribe [5]
  • #1 / May 05, 2011 3:29pm

    I have searched for a few hours on this topic. I have a set of entries I want to display, but depending upon their category, I want it to use a different url path. How do I make this work?

    {exp:weblog:entries weblog="articles" limit="4"}
    
    
    {if category == "221"}
        <a href="http://{title_permalink=">{image}</a>
    {if:else}
        <a href="http://{title_permalink=">{food_front_image}</a>
    {/if}
    
    
    {/exp:weblog:entries}

    What am I missing here?

  • #2 / May 05, 2011 4:32pm

    Mark Bowen

    12637 posts

    Hiya,

    You’ll be needing to take a look at using the {categories} tag pair for this. Something like below should hopefully work for you :

    {exp:weblog:entries weblog="articles" limit="4"}
    
    {categories}
    {if category_id == "221"}
        <a href="http://{title_permalink=">{image}</a>
    {if:else}
        <a href="http://{title_permalink=">{food_front_image}</a>
    {/if}
    {/categories}
    
    {/exp:weblog:entries}

    Hope that helps a bit.

    Best wishes,

    Mark

  • #3 / May 05, 2011 4:36pm

    I had tried something similar but not exactly that. Let me see if it works. Thanks.

  • #4 / May 05, 2011 5:03pm

    Well, that caused nothing to show.

  • #5 / May 05, 2011 5:14pm

    Mark Bowen

    12637 posts

    Do you mean nothing on the page or nothing in the source code?

    Pretty sure it should be working. Perhaps test like this instead :

    {exp:weblog:entries weblog="articles" limit="4"}
    
    {categories}
    {if category_id == "221"}
    Category 221
    {if:else}
    A different category
    {/if}
    {/categories}
    
    {/exp:weblog:entries}

    If that shows some text then perhaps your image variables aren’t working for some reason?

    Best wishes,

    Mark

  • #6 / May 05, 2011 5:21pm

    Nothing shows within the if statements, even with that text thrown in. Is there maybe something missing out of the exp:weblog:entries tag?

  • #7 / May 05, 2011 6:17pm

    Mark Bowen

    12637 posts

    What type of URL are you viewing the template at?

    Perhaps try adding in the dynamic=“off” parameter to the weblog entries tag. See if that helps.

    Best wishes,

    Mark

  • #8 / May 06, 2011 7:40am

    John Henry Donovan

    12339 posts

    Pet Rescue Barbie,

    let us know if the addition of dynamic=“off” made a difference

    If not then try a simple conditional inside there rather than the advanced

    {exp:weblog:entries weblog="articles" limit="4"}
    
    {categories}
    {if category_id != "221"}
    A different category
    {/if}
    {/categories}
    
    {/exp:weblog:entries}
  • #9 / May 06, 2011 12:11pm

    Sadly, neither of those worked.

  • #10 / May 06, 2011 2:45pm

    Lisa Wess

    20502 posts

    Hi, PRB -

    Can you let us know what this outputs?

    {exp:weblog:entries weblog="articles" limit="4"}
    
    <h1>{title}</h1>
    {categories}
    {category_id}: {category_name}
    
    {/categories}
    
    {/exp:weblog:entries}

    Please try this in a totally blank template, with only this code, and give us the link to that test template.

    While you’re doing this, please let us know your version and build. =)

    Thank you!

  • #11 / Jun 29, 2011 8:15am

    redfred

    141 posts

    Something like this might do the trick:

    {exp:weblog:entries weblog="weblog-name"}
    <a href="{path='template-name'}{categories}{category_url_title}{/categories}/{url_title}">
    {/exp:weblog:entries}

    I used this in EE1.6.9

  • #12 / Jun 30, 2011 2:36pm

    Brandon Jones

    5500 posts

    Let us know what you find, Pet Rescue Barbie.

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

ExpressionEngine News!

#eecms, #events, #releases