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 count inside channel entry limit with conditional

October 05, 2012 4:07am

Subscribe [2]
  • #1 / Oct 05, 2012 4:07am

    Corazon

    2 posts

    Hi guys!
    Just having a little trouble with the following procedure. Basically I’m creating a series of feature banner fields (image/title/blurb) with a field to allow site admins to ‘show feature’ on the home page or not to on any given entry. For the most part the following works fine, except however the ability to flag the first entry to set the class as ‘active’.

    {exp:channel:entries channel="article" limit="6" orderby="date" sort="desc"}
    {if feature_article == 'y'}
    <div class="{if count == 1}active {/if}item">Content</div>
    {/if}
    {/exp:channel:entries}

    The feature_article is my switch field to show the banner in the array. If all banners are set to ‘y’ then the ‘active’ class is added to the first entry through the ‘count’ parameter no problems. But as soon as, say the latest entry has feature_article set to ‘n’, the limit parameter seems to include the hidden entry in the count, thus not enabling the active class to the first entry.

    In addition, the true final count is only 5 in the above given circumstance, not 6.

    Is there any way to parse the conditional before the limit count? Or am I doing it completely wrong? Any help is much appreciated - thanks!

     

  • #2 / Oct 05, 2012 4:46am

    Ian Ebden

    312 posts

    If it’s not too late to rethink this, you might consider dropping the feature_article field and use a custom “Featured” status instead? Would save you an {if} statement too.

  • #3 / Oct 05, 2012 4:58am

    Corazon

    2 posts

    Not too late at all! A bit embarrassed to admit after producing quite a few EE sites, I’ve always ignored or scanned by custom statuses without a second glance. Your solution works perfectly Ian.

    Really appreciate your time and effort. Have a great one!

  • #4 / Oct 06, 2012 9:22pm

    Dan Decker

    7338 posts

    Hi Corazon,

    I’m glad Ian’s suggestion was able to get you moving forward.

    I think it would be good to explain your results, however.

    In your code, you are telling EE to grab 6 entries, then operate conditionally on those 6 entries. That’s why you were seeing the phantom count/entry and why your second conditional was failing. Of the 6 latest, the first did not meet the second conditional. Make sense?

    In addition to statuses, which are likely the most elegant approach, you could have used the search= parameter to the same effect.

    Is there anything else I can assist you with?

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

ExpressionEngine News!

#eecms, #events, #releases