Home › Forums › Calendar Products › Events Calendar PRO › Altered a function where should I put it?
- This topic has 4 replies, 2 voices, and was last updated 11 years, 12 months ago by
Barry.
-
AuthorPosts
-
April 8, 2014 at 10:18 pm #129893
Joel
ParticipantI’ve altered the tribe_events_list_the_date_headers function in order to display the days in the loop as well as the month and year that is already displayed.
My question is where should I put the altered function so that it’s saved when new releases come out and overrides/adds to the current function?
my-theme/tribe-events/public/template-tags/loop.php?
April 9, 2014 at 1:18 pm #130195Barry
MemberHi – great question!
Those functions aren’t overrideable quite in the same way as templates so the best approach is to use an appropriate filter, instead.
In this case, the tribe_events_list_the_date_headers filter would work. So simply give your custom function, which could live in your theme’s functions.php file or even a dedicated plugin, its own name and hook it up like this:
add_filter( 'tribe_events_list_the_date_headers', 'your_own_function_name' );Does that help here?
April 9, 2014 at 4:37 pm #130386Joel
ParticipantGreat, thanks!
April 12, 2014 at 8:52 am #131786Joel
ParticipantI’m guessing other people have/will be looking for a way to add dates to the calendar on the list page so here’s the function that I added in my theme’s function.php file:
function add_date_to_events_calendar($html){
$html = ”;
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, ‘j’ );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, ‘j’ );
}
/*
* 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( “<span class=’tribe-events-list-separator-month’><span>%s</span></span>”, tribe_get_start_date( $post, false, ‘F Y’ ) );
}
/*
* If this event year is different to the year of the previous event in the loop,
* and it’s not it’s not the first event in the loop (we don’t want to start the loop with a year separator)
*/
if ( $wp_query->current_post > 0 && $prev_event_year != $event_year ) {
$html .= sprintf( “<span class=’tribe-events-list-separator-year’>%s</span>”, $event_year );
}
/*
* If the event day changed since the last event in the loop,
* or is the same day but the month changed.
*
*/
if ( $wp_query->current_post === 0 || ( $prev_event_day != $event_day || ( $prev_event_day == $event_day && $prev_event_month != $event_month ) ) ) {
$html .= sprintf( “<span class=’tribe-events-list-separator-month’><span>%s</span></span>”, tribe_get_start_date( $post, false, ‘j l’ ) );
}
return $html;
}
add_filter( ‘tribe_events_list_the_date_headers’, ‘add_date_to_events_calendar’ );April 17, 2014 at 7:27 am #135142Barry
MemberThank you for sharing!
-
AuthorPosts
- The topic ‘Altered a function where should I put it?’ is closed to new replies.
