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.

query > weblog:entries > switch - not supposed to work?

September 16, 2008 6:45pm

Subscribe [1]
  • #1 / Sep 16, 2008 6:45pm

    TechWench

    30 posts

    I’m trying to grab the count of a particular category, so if the category has more than 4 posts, I want posts from only that category to display…if it has less than 4 posts, I want to show the 4 recent posts from ALL categories.

    But the logic of my code combined with the parse order is not liking my switch classes…other than the left/right switch, everything else works.

    {exp:query sql="SELECT count(cat_id) AS 'cat_count' FROM exp_category_posts WHERE cat_id='6'"}
                    
    {if cat_count < 4}
    {exp:weblog:entries weblog="work" limit="4" exclude="memberdata|trackbacks"}
    <dl class="{switch="left|right"}">
    <dt>{title}</dt>
    <dd><span class="main_img"><a href="http://{title_permalink=work}" class="fp">{work_imagemain}</a></span></dd>                 
    </dl>
    {/exp:weblog:entries}
    {/if}
    
    {if cat_count >== 4}
    {exp:weblog:entries weblog="work" category="6" limit="4" exclude="memberdata|trackbacks"}
    <dl class="{switch="left|right"}">
    <dt>{title}</dt>
    <dd><span class="main_img"><a href="http://{title_permalink=work}" class="fp">{work_imagemain}</a></span></dd>                 
    </dl>
    {/exp:weblog:entries}
    {/if}
                    
    {/exp:query}

    Am I going to have to do another query within the exp:weblog:entries tag just to get the current count and make the switch manually?

    Edited to add:

    EE: 1.6.4
    Build: 20080808
    URL:  http://m2.westnethost.com - “featured projects” on the index page
    (this is my test site, the actual site is not live yet and can only be accessed by editing hosts files)

  • #2 / Sep 16, 2008 11:43pm

    TechWench

    30 posts

    Well, no matter what I tried, even with parse=inward/outward, it still didn’t work so I just ended up setting and incrementing the count with php.

  • #3 / Sep 17, 2008 1:43pm

    Lisa Wess

    20502 posts

    The reason switch isn’t working for you here is because switch is a valid variable for both the query module and the weblog entries tag.  Therefore, it’s probably switching your query rather than your entries.

    The EE way around this is to embed your weblog entries tag, passing the variables from your query to the embed. Then your switch won’t have a conflict. =)

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

ExpressionEngine News!

#eecms, #events, #releases