tribe_events_list_the_date_headers()
Used in list loop, displays the date headers between events in the loop when the month / year has changed
Source
File: src/functions/template-tags/loop.php
function tribe_events_list_the_date_headers() {
/* Month and year separators (on every month and year change) */
$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' );
$month_year_format = tribe_get_date_option( 'monthAndYearFormat', 'F Y' );
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' );
}
/*
* If the event month changed since the last event in the loop,
* or is the same month but the year changed.
*
*/
if ( $wp_query->current_post === 0 || ( $prev_event_month != $event_month || ( $prev_event_month == $event_month && $prev_event_year != $event_year ) ) ) {
$html .= sprintf( "<h2 class='tribe-events-list-separator-month'><span>%s</span></h2>", tribe_get_start_date( $post, false, $month_year_format ) );
}
echo apply_filters( 'tribe_events_list_the_date_headers', $html, $event_month, $event_year );
}
}