Skip to content

Instantly share code, notes, and snippets.

@jessor
Last active February 24, 2016 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessor/f8aef51fd4cd8a38dc6c to your computer and use it in GitHub Desktop.
Save jessor/f8aef51fd4cd8a38dc6c to your computer and use it in GitHub Desktop.
Group by day for List view of The Events Calendar
<?php
/*
* Modification of tribe_events_list_the_date_headers() for date grouping
* call this instead in tribe-events/list/loop.php
*
* @source the-events-calendar/src/functions/template-tags/loop.php
*/
function conact_list_the_date_headers() {
$show_headers = apply_filters( 'tribe_events_list_show_date_headers', true );
$html = '';
if ( $show_headers ) {
global $post, $wp_query;
$event_year = tribe_get_start_date( $post, false, 'Y' );
$event_month = tribe_get_start_date( $post, false, 'm' );
$event_day = tribe_get_start_date( $post, false, 'd' );
$month_year_format = tribe_get_date_option( 'monthAndYearFormat', 'F Y' );
$day_format = tribe_get_date_option( 'weekDayFormat', 'd' );
if ( $wp_query->current_post > 0 ) {
$prev_post = $wp_query->posts[ $wp_query->current_post - 1 ];
$prev_event_year = tribe_get_start_date( $prev_post, false, 'Y' );
$prev_event_month = tribe_get_start_date( $prev_post, false, 'm' );
$prev_event_day = tribe_get_start_date( $prev_post, false, 'd' );
}
if ( $wp_query->current_post === 0 || ( $prev_event_day != $event_day || ( $prev_event_day == $event_day && $prev_event_month != $event_month ) || ( $prev_event_month == $event_month && $prev_event_year != $event_year ) ) ) {
$html .= sprintf(
'</dd></dl><dl><dt>' . "<span class='tribe-events-list-separator-month'><span>%s</span></span>" . '</dt><dd>',
tribe_get_start_date( $post, false, $day_format )
);
echo apply_filters(
'tribe_events_list_the_date_headers',
$html,
$event_month,
$event_year
);
}
}
}
function conact_close_dl() {
echo '</dd></dl>';
}
add_action( 'tribe_events_after_loop', 'conact_close_dl' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment