This is a bit of a hard one to explain, but I will do my best. If you need any clarification just ask :)
I have a template that needs to display a list of 3 upcoming events, listed by date ascending (nearest first, farthest away last). I have this working with the following code:
{exp:channel:entries channel="news-article" dynamic="no" order_by="entry_date" sort="asc" category="1" sticky="no" show_future_entries="yes"}
{if '{entry_date format="%Y%m%d"}' >= '{current_time format="%Y%m%d"}'}
<article>
<a href="{url_title_path='news'}">
<p>
{title}
<span class="time-block">{entry_date {long-date}}</span>
</p>
</a>
</article>
{/if}
{/exp:channel:entries}
However, this shows all future events, not just the closest 3. I have tried adding limit="3"
to the channel entries tag but as there are past events, the conditional is never true so nothing shows at all.
So I tried adding a PHP counter to it like so:
<?php $counter = 0; ?>
{exp:channel:entries channel="news-article" dynamic="no" order_by="entry_date" sort="asc" category="1" sticky="no" show_future_entries="yes"}
{if '{entry_date format="%Y%m%d"}' >= '{current_time format="%Y%m%d"}'}
<?php if ($counter<3): ?>
<article>
<a href="{url_title_path='news'}">
<p>
{title}
<span class="time-block">{entry_date {long-date}}</span>
</p>
</a>
</article>
<?php $counter ++;
endif; ?>
{/if}
{/exp:channel:entries}
Parsing PHP on input still displays all results today or in the future, and parsing PHP on output displays nothing. Does anybody know how to get something like this working?
Thanks in advance!