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.

Using conditional with {exp:query} results

May 20, 2009 11:05pm

Subscribe [1]
  • #1 / May 20, 2009 11:05pm

    Nick Gascoigne

    14 posts

    I’ve discovered something a bit strange…I’m using a method from the wiki to display a list of categories and the post counts for each category. It works fine.

    The only problem is when I want to check if one of the query results is equal to a certain value, so I can indicate the current category. When I try to do that all I get is a blank page.

    Here’s the code:

    <ul id="nav_categories" class="categories_list">
    {exp:query sql="SELECT count(exp_category_posts.entry_id) AS post_count, 
    exp_category_posts.cat_id, exp_categories.cat_name AS cat_name
    FROM exp_categories, exp_category_posts, exp_weblog_titles
    WHERE exp_category_posts.cat_id = exp_categories.cat_id AND parent_id='0'
    AND exp_weblog_titles.weblog_id = '2'
    AND exp_weblog_titles.entry_id = exp_category_posts.entry_id
    GROUP BY exp_categories.cat_name"}
    
    <!-- this is the conditional bit where it falls over -->
    <li><a href="http://{path=calendar/categories}C{cat_id}/" class="current">{cat_name} <span>({post_count})</span></a></li>
    
    {/exp:query}
    </ul>

    I’m trying to insert

    {if {cat_name} == 'Education'} class="current"{/if}

    inside the a tag

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

ExpressionEngine News!

#eecms, #events, #releases