Remove times from Event Schedule Details function?

Home Forums Calendar Products Events Calendar PRO Remove times from Event Schedule Details function?

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1134679
    David
    Participant

    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

    #1134681
    David
    Participant

    Or, 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.

    #1134682
    David
    Participant

    This reply is private.

    #1135131
    Nico
    Member

    Howdy 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,
    Nico

    #1135613
    David
    Participant

    Hi 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.

    #1135680
    David
    Participant

    Hello 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
    Dave

    #1135683
    David
    Participant

    This reply is private.

    #1135735
    David
    Participant

    This reply is private.

    #1136297
    Nico
    Member

    This reply is private.

    #1136329
    David
    Participant

    This reply is private.

    #1136443
    Nico
    Member

    David,

    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,
    Nico

    #1136687
    David
    Participant

    Awesome, 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 :)
    #1137533
    Brook
    Participant

    Howdy 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

    #1140463
    David
    Participant

    Thank you Brook and/or Nico! Worked great!

    #1140466
    Nico
    Member

    Thanks 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

Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘Remove times from Event Schedule Details function?’ is closed to new replies.