Last active
February 24, 2016 13:44
-
-
Save jessor/f8aef51fd4cd8a38dc6c to your computer and use it in GitHub Desktop.
Group by day for List view of The Events Calendar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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