Skip to content

Instantly share code, notes, and snippets.

@vicskf
Last active June 13, 2017 02:45
Show Gist options
  • Save vicskf/73fb04230fb4948f53369471787f52ea to your computer and use it in GitHub Desktop.
Save vicskf/73fb04230fb4948f53369471787f52ea to your computer and use it in GitHub Desktop.
TEC - Adds day headers between events in the loop when the day has changed
<?php
/**
* Adds day headers between events in the loop when the day has changed
*
**/
add_filter( 'tribe_events_list_the_date_headers', 'the_date_headers_add_day_header_separator', 10, 1 );
function the_date_headers_add_day_header_separator ( $html ){
if ( !empty( $html ) ) {
return $html;
}
global $post, $wp_query;
$event_day = tribe_get_start_date( $post, false, 'j' );
$date_without_year = tribe_get_date_option( 'dateWithoutYearFormat', 'F j' );
if ( $wp_query->current_post > 0 ) {
$prev_post = $wp_query->posts[ $wp_query->current_post - 1 ];
$prev_event_day = tribe_get_start_date( $prev_post, false, 'j' );
}
/*
* If the day changed since the last event in the loop
*/
if ( $wp_query->current_post === 0 || ( $prev_event_day != $event_day ) ) {
$html .= sprintf( "<span class='tribe-events-list-separator-month'><span>%s</span></span>", tribe_get_start_date( $post, false, $date_without_year ) );
}
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment