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.

If Statement + Category_ID Conditional On Individual Weblog Entry "Page"

May 07, 2009 12:09pm

Subscribe [2]
  • #1 / May 07, 2009 12:09pm

    In Like A Lion

    47 posts

    I’m having trouble using an if statement with a weblog entry category_id as a the conditional.  This page doesn’t have category in its URL segments - its a ‘full post’, permalink style page. Because of that I thought it might be messing up the category_id, however it’s working without the if statement earlier in the code:

    <body class="bodyBlogs" id="blogs{exp:weblog:entries weblog="law-blogs"  limit="1" disable="trackbacks|comments|member_data|pagination"}{categories}{category_id}{/categories}{/exp:weblog:entries}">

    prints as this:

    <body class="bodyBlogs" id="blogs6">

    So, using the same idea, I’m using an if, if:else statement to print different headings, depending on the category:

    <h2 id="title">{exp:weblog:entries weblog="law-blogs"  limit="1" disable="trackbacks|comments|member_data|pagination"}{if category_id == '5'}Labor and Employment Law Blog{if:elseif category_id == '6'}Mississippi Alcohol and Liquor{/if}{/exp:weblog:entries}</h2>

    But that is currently printing nothing.  I don’t know if I’m screwing up some syntax, or if I’m misunderstanding the concept of what I’m trying to do.

    Here is a live example page:

    http://www2.watkinsludlam.com/law-blogs/post/and-speaking-of-sunday-sales/

    Thanks in advance, guys!

  • #2 / May 07, 2009 12:16pm

    Lisa Wess

    20502 posts

    If you compare your two statements you’ll notice the one with the conditionals is missing the categories variable pair around the category variables. =)

  • #3 / May 07, 2009 12:24pm

    In Like A Lion

    47 posts

    Quick catch!  Thanks. 

    Categories are something I’m still waiting on an entire “lightbulb moment”.  For completion sake, here is the updated code that worked:

    <h2 id="title">{exp:weblog:entries weblog="law-blogs"  limit="1" disable="trackbacks|comments|member_data|pagination"}{categories}{if category_id == '5'}Labor and Employment Law Blog{if:elseif category_id == '6'}Mississippi Alcohol and Liquor{/if}{/categories}{/exp:weblog:entries}</h2>

    Cheers!

  • #4 / May 07, 2009 12:27pm

    Sue Crocker

    26054 posts

    Looks like Lisa was able to help. Don’t hesitate to post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases