Hi Stephen,
I need to modify the shortcode-event-list.php template to output a simple list of events grouped by Month. I emailed you about this before. My attempt is below, however, it’s outputting the month before every list item. I only need to output the name of the month if it changes.
Here’s the loop from the template that I’ve added code to – as ever, appreciate your help to get it right:
<?php if( $eo_event_loop->have_posts() ): ?>
<ul <?php echo $id; ?> class="<?php echo esc_attr($classes);?> eo-events-entry-list" >
<?php while( $eo_event_loop->have_posts() ): $eo_event_loop->the_post(); ?>
<?php
//Generate HTML classes for this event
$eo_event_classes = eo_get_event_classes();
//For non-all-day events, include time format
$format = ( eo_is_all_day() ? $date_format : $date_format.' '.$time_format );
?>
<li class="<?php echo esc_attr(implode(' ',$eo_event_classes)); ?>" >
<?php echo __('','eventorganiser') . ' '.eo_get_the_start('jS F'); ?> - " title="<?php the_title_attribute(); ?>" ><?php the_title(); ?>
<?php
if( !$previous_event_id || ( eo_get_the_start( 'Y-m', $previous_event_id, null, $previous_occurrence_id ) != eo_get_the_start( 'Y-m', $current_event_id, $current_occurrence_id ) ) ){
echo eo_get_the_start('F');
}
?>
<?php endwhile; ?>

Paul Oaten
any help with this one is appreciated 🙂

Paul Oaten
You need to set the $previous_event_id
and $previous_occurrence_id
so that they they are set to the corresponding values of the previous event ($post->ID
, $post->occurrence_id
)(or false
if you’re on the first event. ). Essentially you’re then looking for when the event’s month (as determined by Y-m
) changes.
(Just so you know, these forums use markdown. To write blocks of code, leave a blank line and indent by four spaces. Or just write out any code (without any escaping), highligh it and click the curly braces in the toolbar)

Stephen Harris