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.

Category Conditionals

December 02, 2012 7:57am

Subscribe [2]
  • #1 / Dec 02, 2012 7:57am

    kohnt01

    11 posts

    I’d like to change the category shown of a exp:channel:entries tag based on the page it is on.

    Something like this:

    {exp:channel:entries channel="news" dynamic="no" limit="12" {if segment_1 == "ps3"} category="28" {if:elseif segment_1 == "xbox-360"} category="29" {/if}  paginate="bottom"}

    OR:

    {if segment_1 == "ps3"}
    
    {exp:channel:entries channel="news" dynamic="no" limit="12" category="28" paginate="bottom"}
    
    {if:elseif segment_1 == "xbox-360"}
    
    {exp:channel:entries channel="news" dynamic="no" limit="12" category="29" paginate="bottom"}
    
    {if:else} 
    
    {exp:channel:entries channel="news" dynamic="no" limit="12" paginate="bottom"}
    
    {/if}

    But neither of those are working. I’m new to EE so I’m not sure if they’re correct, but I’m not sure what else I could do. Any suggestions?

  • #2 / Dec 02, 2012 9:19am

    MadWebDesigns

    147 posts

    Hi kohnt01,

    Try the following:

    {exp:channel:entries channel="news" dynamic="no" limit="12" category="{if segment_1 == 'ps3'}28{if:elseif segment_1 == 'xbox-360'}29{/if}"  paginate="bottom"}

    The reason why your alternate method is not working is because of EE’s parse order. I hope this helps.

    Cheers,

    Mike

  • #3 / Dec 02, 2012 9:36am

    kohnt01

    11 posts

    Hi kohnt01,

    Try the following:

    {exp:channel:entries channel="news" dynamic="no" limit="12" category="{if segment_1 == 'ps3'}28{if:elseif segment_1 == 'xbox-360'}29{/if}"  paginate="bottom"}

    The reason why your alternate method is not working is because of EE’s parse order. I hope this helps.

    Cheers,

    Mike

    Thanks for the quick response, but unfortunately it’s just not working.

    For some reason when I enter your code it’s not showing the entries at all. I’ve tested the ps3 segment_1 and that’s working fine so the condition itself shouldn’t be the issue.

    Any idea?

     

  • #4 / Dec 02, 2012 10:55am

    MadWebDesigns

    147 posts

    Does this work:

    {exp:channel:entries channel="news" dynamic="no" limit="12" category="{if segment_1 == 'ps3'}28{/if}"  paginate="bottom"}

    If so, then change your code to the following:

    {exp:channel:entries channel="news" dynamic="no" limit="12" category="{if segment_1 == 'ps3'}28{/if}{if segment_1 == 'xbox-360'}29{/if}"  paginate="bottom"}

    Cheers,

    Mike

  • #5 / Dec 02, 2012 11:34am

    kohnt01

    11 posts

    Does this work:

    {exp:channel:entries channel="news" dynamic="no" limit="12" category="{if segment_1 == 'ps3'}28{/if}"  paginate="bottom"}

    If so, then change your code to the following:

    {exp:channel:entries channel="news" dynamic="no" limit="12" category="{if segment_1 == 'ps3'}28{/if}{if segment_1 == 'xbox-360'}29{/if}"  paginate="bottom"}

    Cheers,

    Mike

    It worked, looks like it doesn’t like the elseif condition lol.

    Many thanks,

  • #6 / Dec 02, 2012 1:16pm

    MadWebDesigns

    147 posts

    I’m glad that fix it for you. All the best.

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

ExpressionEngine News!

#eecms, #events, #releases