Home › Forums › Calendar Products › Events Calendar PRO › Remove times from Event Schedule Details function?
- This topic has 15 replies, 4 voices, and was last updated 7 years, 9 months ago by David.
-
AuthorPosts
-
July 1, 2016 at 4:34 pm #1134679DavidParticipant
Hi there, I’m trying to customize the map view with list of events beneath and am using this to display the date of each event, but it is also displaying the time:
<?php echo tribe_events_event_schedule_details(); ?>
I started off using this to display the date only and remove the time, but didn’t allow for if an event spanned more than one day like the one above:
<?php echo tribe_get_start_date( null, false ); ?>
Any advice on how to remove the “@ (time)” from the output of tribe_events_event_schedule_details ?
Thanks
July 1, 2016 at 4:36 pm #1134681DavidParticipantOr, if there’s a different function I should use, or some other/better way to make it so the times don’t display but allows for a multi-day event, that’s fine too.
July 1, 2016 at 4:37 pm #1134682DavidParticipantThis reply is private.
July 4, 2016 at 10:15 am #1135131NicoMemberHowdy David,
Welcome to our support forums and thanks for reaching out to us!
I can help you here, but first please let me know if your intention is to modify this output for all event views or just for map view. There are some filters in tribe_events_event_schedule_details that can be used to modify this, so please do let me know about the scope of this change so I can prepare the snippet for you.
Thanks,
NicoJuly 5, 2016 at 10:03 am #1135613DavidParticipantHi Nico — good question. I will be working on our event detail page today and will let you know whether I need the same situation there or not.
July 5, 2016 at 12:27 pm #1135680DavidParticipantHello again Nico,
Yes, we’d like to modify the output on both the map view and the event detail page. We are not using any other views, so global should be fine.
Also wondering how we display the start and end time separately… can I use that function again but strip out the dates part?
So in the end, we’d have the following:
Date start – Date end (if multiple days, or just date start if single day)
Start time – End time (start and end for all events, even single day ones)Thanks
DaveJuly 5, 2016 at 12:34 pm #1135683DavidParticipantThis reply is private.
July 5, 2016 at 2:47 pm #1135735DavidParticipantThis reply is private.
July 6, 2016 at 3:26 pm #1136297NicoMemberThis reply is private.
July 6, 2016 at 4:32 pm #1136329DavidParticipantThis reply is private.
July 7, 2016 at 5:42 am #1136443NicoMemberDavid,
Paste the snippet below in your theme’s (or child theme’s) functions.php file to remove the @ time part from the tribe_events_event_schedule_details function:
/* Do not output the '@ time' part of the schedule details */
function tribe_modify_schedule_details ( $settings ) {$settings['time'] = false;
return $settings;
}add_filter( 'tribe_events_event_schedule_details_formatting', 'tribe_modify_schedule_details' );
Regarding the time you can add this custom function to the functions.php file and use it in the templates (echo tribe_get_event_times();) :
/* Tribe return start time and end time with proper format and separator */
function tribe_get_event_times ( $event = null ) {if ( is_null( $event ) ) {
global $post;
$event = $post;
}$time_format = get_option( 'time_format' );
$time_range_separator = tribe_get_option( 'timeRangeSeparator', ' - ' );return tribe_get_start_date( $event, false, $time_format ) . ' ' . $time_range_separator . ' ' . tribe_get_end_date( $event, false, $time_format );
}
Please let me know if this makes it work as you need,
Best,
NicoJuly 7, 2016 at 10:15 am #1136687DavidParticipantAwesome, thanks Nico. These work great. Nice work!
Follow up questions:
1) can I display the months as abbreviations, such as “Sept” instead of “September”, and can that be done at the page level rather than globally?
2) can I also display the year? So “July 14, 2016”?
And on a multi-day event, can I display it once, such as “July 14 – 16, 2016” rather than “July 14, 2016 – July 16, 2016”?- This reply was modified 7 years, 10 months ago by David. Reason: Follow up questions :)
July 8, 2016 at 1:20 pm #1137533BrookParticipantHowdy David,
Nico is a bit tied up at the moment, but I would love to help you with this as best I’m able.
This would seem to do what you’re after:
/** * Modifies tribe_events_event_schedule_details format * * @param string $schedule the output HTML * @param int $event_id post ID of the event we are interested in * @param string $before part of the HTML wrapper that was prepended * @param string $after part of the HTML wrapper that was appended */ function tribe_events_event_schedule_details_custom ( $schedule, $event_id = null, $before = '', $after = '' ) { $inner = '<span class="tribe-event-date-start">'; $format = 'M j, Y'; $time_format = get_option( 'time_format' ); $datetime_separator = tribe_get_option( 'dateTimeSeparator', ' @ ' ); $time_range_separator = tribe_get_option( 'timeRangeSeparator', ' - ' ); $settings = array( 'show_end_time' => false, 'time' => false, ); /** * @var $show_end_time * @var $time */ extract( $settings ); if ( tribe_event_is_multiday( $event_id ) ) { // multi-date event $format2ndday = apply_filters( 'tribe_format_second_date_in_range', $format, $event_id ); if ( tribe_event_is_all_day( $event_id ) ) { $inner .= tribe_get_start_date( $event_id, true, 'M j' ); $inner .= '</span>' . $time_range_separator; $inner .= '<span class="tribe-event-date-end">'; $end_date_full = tribe_get_end_date( $event_id, true, Tribe__Date_Utils::DBDATETIMEFORMAT ); $end_date_full_timestamp = strtotime( $end_date_full ); // if the end date is <= the beginning of the day, consider it the previous day if ( $end_date_full_timestamp <= strtotime( tribe_beginning_of_day( $end_date_full ) ) ) { $end_date = tribe_format_date( $end_date_full_timestamp - DAY_IN_SECONDS, false, $format2ndday ); } else { $end_date = tribe_get_end_date( $event_id, false, $format2ndday ); } $inner .= $end_date; } else { $inner .= tribe_get_start_date( $event_id, false, 'M j' ) . ( $time ? $datetime_separator . tribe_get_start_date( $event_id, false, $time_format ) : '' ); $inner .= '</span>' . $time_range_separator; $inner .= '<span class="tribe-event-date-end">'; $inner .= tribe_get_end_date( $event_id, false, $format2ndday ) . ( $time ? $datetime_separator . tribe_get_end_date( $event_id, false, $time_format ) : '' ); } } elseif ( tribe_event_is_all_day( $event_id ) ) { // all day event $inner .= tribe_get_start_date( $event_id, true, $format ); } else { // single day event if ( tribe_get_start_date( $event_id, false, 'g:i A' ) === tribe_get_end_date( $event_id, false, 'g:i A' ) ) { // Same start/end time $inner .= tribe_get_start_date( $event_id, false, $format ) . ( $time ? $datetime_separator . tribe_get_start_date( $event_id, false, $time_format ) : '' ); } else { // defined start/end time $inner .= tribe_get_start_date( $event_id, false, $format ) . ( $time ? $datetime_separator . tribe_get_start_date( $event_id, false, $time_format ) : '' ); $inner .= '</span>' . ( $show_end_time ? $time_range_separator : '' ); $inner .= '<span class="tribe-event-time">'; $inner .= ( $show_end_time ? tribe_get_end_date( $event_id, false, $time_format ) : '' ); } } $inner .= '</span>'; /** * Provides an opportunity to modify the *inner* schedule details HTML (ie before it is * wrapped). * * @param string $inner_html the output HTML * @param int $event_id post ID of the event we are interested in */ $inner = apply_filters( 'tribe_events_event_schedule_details_inner', $inner, $event_id->ID ); // Wrap the schedule text $schedule = $before . $inner . $after; return $schedule; } add_filter( 'tribe_events_event_schedule_details', 'tribe_events_event_schedule_details_custom', 10, 4 );
You could replace the first snippet Nico shared with this, as this also removes the time.
Did that do what you need?
Cheers!
– Brook
July 15, 2016 at 11:08 am #1140463DavidParticipantThank you Brook and/or Nico! Worked great!
July 15, 2016 at 11:11 am #1140466NicoMemberThanks for the heads-up David 🙂
I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.
Have a great weekend,
Nico -
AuthorPosts
- The topic ‘Remove times from Event Schedule Details function?’ is closed to new replies.