Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created November 15, 2016 17:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/f0d703f186bc4689f02741205541d576 to your computer and use it in GitHub Desktop.
Save joshfeck/f0d703f186bc4689f02741205541d576 to your computer and use it in GitHub Desktop.
This is an alternative way to display dates and times for the Event Espresso event page. Formats a single date time that spans multiple days as “Starts at <time> on <date> Ends at <time> on <date>”.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
function espresso_list_of_event_dates( $EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL ) {
$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
$date_format = apply_filters( 'FHEE__espresso_list_of_event_dates__date_format', $date_format );
$time_format = apply_filters( 'FHEE__espresso_list_of_event_dates__time_format', $time_format );
EE_Registry::instance()->load_helper( 'Event_View' );
$datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, $show_expired, FALSE, $limit );
if ( ! $format ) {
return apply_filters( 'FHEE__espresso_list_of_event_dates__datetimes', $datetimes );
}
if ( is_array( $datetimes ) && ! empty( $datetimes )) {
global $post;
$html = $format ? '<ul id="ee-event-datetimes-ul-' . $post->ID . '" class="ee-event-datetimes-ul">' : '';
foreach ( $datetimes as $datetime ) {
if ( $datetime instanceof EE_Datetime ) {
$html .= '<li id="ee-event-datetimes-li-' . $datetime->ID() . '" class="ee-event-datetimes-li">';
$datetime_name = $datetime->name();
$html .= ! empty( $datetime_name ) ? '<strong>' . $datetime_name . '</strong>' : '';
$html .= ! empty( $datetime_name ) && $add_breaks ? '<br />' : '';
$html .= '<span class="dashicons dashicons-calendar"></span>';
$d1 = $datetime->start_date();
$d2 = $datetime->end_date();
$t1 = $datetime->start_time();
$t2 = $datetime->end_time();
if ($d1 == $d2) {
$html .= $datetime->start_date($date_format) . ' ' . $datetime->time_range( $time_format );
} else {
$html .= 'Starts at ' . $t1 . ' on ' . $d1;
$html .= '<br>';
$html .= 'Ends at ' . $t2 . ' on ' . $d2;
}
$datetime_description = $datetime->description();
$html .= ! empty( $datetime_description ) && $add_breaks ? '<br />' : '';
$html .= ! empty( $datetime_description ) ? ' - ' . $datetime_description : '';
$html = apply_filters( 'FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime );
$html .= '</li>';
}
}
$html .= $format ? '</ul>' : '';
} else {
$html = $format ? '<p><span class="dashicons dashicons-marker"></span>' . __( 'There are no upcoming dates for this event.', 'event_espresso' ) . '</p><br/>' : '';
}
if ( $echo ) {
echo $html;
return '';
}
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment