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.

Linking content to different templates based on category

December 09, 2010 2:31am

Subscribe [3]
  • #1 / Dec 09, 2010 2:31am

    Nick Foxall

    189 posts

    Hi,

    I’m trying to link various headlines from the home page of a site to different templates, based on the category assigned to that entry. e.g. if if an entry is assigned the category of “Press Release” I want the page link to go to the Press release template. if the entry is assigned “Featured Article”, I want it to go to the Features template.

    This is my code:

    {exp:weblog:entries site="mysite" weblog="mymedia" disable="member_data|pagination|trackbacks|comments"}                            
     {categories}
        {if category_id == "1"}<a href="http://{path=%27news/index%27}" class="box">_    {if:else}_    <a href="{path='core/featured'}" class="box">_    {/if}_{/categories}_<div class="box-image">_    {asset_image}{asset_image_file}{/asset_image}    _</div>_<span class="box-holder"><strong>{title}</strong></span>_</a>
    {/exp:weblog:entries}

    ..and it ain’t working. Everything is just going to the ‘core/featured’ template. I’ve also tried

    {title_permalink='blah/blah'}

    and that doesn’t work either. Not sure what I’m doing wrong here :-(

    EE 1.7.0 Build 20101018

    Nik

  • #2 / Dec 09, 2010 4:48pm

    Ingmar

    29245 posts

    Is the category_id, in fact, 1? Does it display as such on its own?

  • #3 / Dec 10, 2010 12:29am

    Nick Foxall

    189 posts

    I’m not quite sure what you mean, but yes “1” is a valid category ID, corresponding the the category name of “Press Release”. I can get it to sort if I use the weblog categories tag, thus:

    {exp:weblog:categories site="mpalibrary" weblog="media_assets" backspace="6"}
    {if category_id == "1"}
         <a href="http://{path=news/index}">{category_name}</a>
    
    {if:else}
         <a href="http://{path=core/featured}">{category_name}</a>
    
    {/if}
    {/exp:weblog:categories}

    ...but it doesn’t work inside a weblog:entries pair. I’ve also tried it with

    {if category_name == "Press Release"}

    ... and it still doesn’t work. What am I missing here?

    Nik

  • #4 / Dec 10, 2010 3:40pm

    Greg Salt

    3988 posts

    Hi Nick,

    The categories tag pair in the weblog entries tag does not support conditionals in this way. Have you thought about creating category custom fields to hold your template paths on a per category basis?

    Cheers

    Greg

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

ExpressionEngine News!

#eecms, #events, #releases