Hi,
I have the short code [eo_events]
on a page titled “Workshops”.
How can I group my event list on that page with the shortcode so that it groups the events by month with a label for each month between each group?
That page lists all events for the year currently.
Thanks!

Don West
Yay! After 4 hours of dinkin’ around with some other code I found here on the forum I figured this out 🙂 This will list your events grouped by month with a month header for each group. Simply use the shortcode [eo_events]
on your events page (you will have to create that).
Here is the code for others to use:
<?php
/**
* Add this to your theme for it to take affect.
*/
global $eo_event_loop,$eo_event_loop_args;
//Date % Time format for events
$date_format = get_option('date_format');
$time_format = get_option('time_format');
//The list ID / classes
$id = ( $eo_event_loop_args['id'] ? 'id="'.$eo_event_loop_args['id'].'"' : '' );
$classes = $eo_event_loop_args['class'];
$current_month = false;
?>
<?php if( $eo_event_loop->have_posts() ): ?>
<?php while( $eo_event_loop->have_posts() ): $eo_event_loop->the_post(); ?>
<?php
if( $current_month != eo_get_the_start('m') ){
//End previous group
echo '</ul>';
//Start new group
echo '<h3>'.eo_get_the_start('F Y').'</h3>';
echo '<ul>';
}
$current_month = eo_get_the_start('m');
//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)); ?>" >
<a href="<?php the_permalink();?>" title="<?php the_title_attribute(); ?>" >
<?php the_title(); ?>
</a>
<?php echo __('<br>','eventorganiser') . ' '.eo_get_the_start($format). ' to ' .eo_get_the_end($time_format); ?>
</li>
<?php endwhile; ?>
<?php elseif( ! empty($eo_event_loop_args['no_events']) ): ?>
<ul id="<?php echo esc_attr($id);?>" class="<?php echo esc_attr($classes);?>" >
<li class="eo-no-events" > <?php echo $eo_event_loop_args['no_events']; ?> </li>
</ul>
<?php endif; ?>
-
This reply was modified 10 years, 1 month ago by
Stephen Harris.

Don West
Thanks for posting this Don. I should add that the template file in which to put the above should be called shortcode-event-list.php
.

Stephen Harris
You’re welcome!
And yes, I should have mentioned that it needs to be pasted into the proper template and said template should reside in the theme folder of the site so as not to be overwritten when the plugin is updated 😉 See the documentation on editing templates.

Don West
Quick question on the above modification Stephen…
Is there a simple way to NOT list any of the events that have already ended? Currently the code lists all events per month.
Thanks!

Don West
Yes, where you are using the shortcode you can use the event_end_after
attribute:
[eo_events event_end_after='now']
(see the shortcode documentation for more details)

Stephen Harris
Ahhh! Thank you!
Should have remembered that!

Don West