1

I'm displaying a list of categories, and I want to add a little "new" icon next to the category name if one or more entries in that category have been created in the last day. But I can't figure out how to display code just once if multiple entries return true. I got this far using GWCode Categories and MX Calculator:

{exp:gwcode_categories
    cat_id='4'
    depth='2'
    show_empty='no'
    style='linear'
    variable_prefix='gw:'
    parse='inward'
}
    <li>
        <a href="{path='topics/{gw:cat_url_title}'}">
            {gw:cat_name}
            <span aria-hidden="true" data-icon=""></span>
            {!-- If an entry in this category has been added in the last day, add the "new" icon --}
            {exp:channel:entries
                channel='{sp_channels}'
                dynamic='no'
                category='{gw:cat_id}'
                disable='categories|pagination|member_data|custom_fields'
            }
                {exp:mx_calc expression="{current_time} - 86400"}
                    {if {entry_date} > {calc_result}}
                         <b class="new">New</b>
                    {/if}
                {/exp:mx_calc}
            {/exp:channel:entries}
        </a>
    </li>
{/exp:gwcode_categories}

But that outputs the "new" tag once for every entry that passes the conditional.

How do I get the code to output just once if any entries return true?

1 Answer 1

2

If you just add a limit="1" parameter to the channel entries tag it will pull the most recent entry anyway - if you think about it, you only really need to see if that single entry was added in the last day, not the whole lot.

1
  • Ah, of course! That didn't even occur to me, thanks!
    – kmgdev
    Commented May 2, 2013 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.