Support

Account

Home Forums General Issues List events by date Reply To: List events by date

  • You could check to see if the date has changed from the last event displayed, and if it has, then you display the date; otherwise you just display the event.. something along the lines of:

    
    // initialize the last displayed date.. since this is before the loop, we'll just make it an empty string
    $lastDate = '';
    
    while ($schedule_query->have_posts()) : $schedule_query->the_post(); ?>
    <?php // now that we're in the loop, start outputting events ?>
    <div class="screening">
    						<h2><strong><?php $date = DateTime::createFromFormat('Ymd', get_field('screening_date'));
    
    // now that we have the event's date, see if it matches the last date displayed.. if not, we'll update $lastDate with the event's date and display it
    
    if ($date != $lastDate) {
    $lastDate = $date;
    echo $date->format('F d, Y'); ?>, </strong></h2>
    }
    
    ...
    endwhile;
    ?>