0

I feel like I have seen a solution to my issue in the EE docs before, but now I can't find what I'm looking for. I would like to exclude some information from repeating inside of a channel entries loop, i.e. the header of the section. the reason for this is because i would like to display a different header-type depending on the amount of information that's returned (therefore, I can't just put the header outside of the loop).

In this example, I'd like Upcoming Events to appear only once, but i'd like the ul div to repeat:

{exp:channel:entries  site="default_site" channel="events" sort="asc" limit="8"}
    {if total_results == "7"}
        <h2>UPCOMING EVENTS</h2>
    {if:else}
        <h4>UPCOMING EVENTS</h4>
    {/if}
    <ul class="list">
        <li>{event_short_name}</li>
    </ul>
{/exp:channel:entries}

1 Answer 1

2

If you have 7 results, with your code above, then total_results will be 7 every time it goes around the loop, which is why you see UPCOMING EVENTS more than once.

Instead, try using

{if count==1}
    <h2>UPCOMING EVENTS</h2>
{/if}

To output something just at the start of the loop. You could put your conditional inside that one if you want to display a different heading depending on how many results there are.

{if count==1}
    {if total_results == "7"}
        <h2>UPCOMING EVENTS</h2>
    {if:else}
        <h4>UPCOMING EVENTS</h4>
    {/if}
{/if}
0

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.