I have custom date fields for an “Upcoming Events” listing. I am showing current and upcoming events using conditionals. I want to only list the next 5 events that are coming up. However, as you might have guessed, I’m running into an issue because of the past events in the system.
The limit parameter takes into account all of the events, including the ones in the past that I don’t want to show. I know a lot of people have solved this problem using the entry_date and the start_on parameters. This is not an option for me. I have content editors who have trained to use the custom date field and are not computer savvy. There are also hundred of events already in the system that use the custom date fields.
Here is my code that works without the limit:
{exp:weblog:entries weblog="upcoming-events" dynamic="off" orderby="event_start_date" sort="asc" }
{if event_end_date > current_time || "{event_start_date format="%Y-%m-%d %H:%i"}" >= "{today}" || "{event_end_date format="%Y-%m-%d %H:%i"}" >= "{today}"}
{event_start_date format="%m/%d/%y"} - {event_end_date format="%m/%d/%y"}
{title}
{/if}
{/exp:weblog:entries}Could there be a way to do this with php?
I tried to set a counter but I got the same results.
<?php
$count = 0;
$limit = 4;
?>
{exp:weblog:entries weblog="upcoming-events" dynamic="off" orderby="event_start_date" sort="asc" }
<?php
if ($count < $limit)
{
?>
{if "{event_start_date format="%Y-%m-%d %H:%i"}" >= "{today}" || "{event_end_date format="%Y-%m-%d %H:%i"}" >= "{today}"}
{event_start_date format="%m/%d/%y"} - {event_end_date format="%m/%d/%y"}
{title}
<?php
$count++;
?>
{/if}
<?php
}
?>
{/exp:weblog:entries}