Last active
February 16, 2021 02:04
-
-
Save joshfeck/c4dbc30d2d464d418b4957715c7bde0d to your computer and use it in GitHub Desktop.
A shortcode to display EE4 events in a similar way that EE3 did. With the Smoothness jQuery UI styles. Add this code to a site-specific plugin, activate it, then add [espresso_legacy_events] to a WordPress page or post.
This file contains 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 // only add this opening PHP tag if starting with a new file with no opening PHP tag | |
function my_ee_legacy_events_shortcode($args) { | |
if(!class_exists('EventEspresso\core\domain\services\wp_queries\EventListQuery')){ | |
return; | |
} | |
global $wp_scripts; | |
// get registered script object for jquery-ui | |
$ui = $wp_scripts->query('jquery-ui-core'); | |
// tell WordPress to load the Smoothness theme from Google CDN | |
$protocol = is_ssl() ? 'https' : 'http'; | |
$url = "$protocol://ajax.googleapis.com/ajax/libs/jqueryui/{$ui->ver}/themes/smoothness/jquery-ui.min.css"; | |
wp_enqueue_style('jquery-ui-smoothness', $url, false, null); | |
$args = shortcode_atts( | |
array( | |
'limit' => 100, | |
'show_expired' => FALSE, | |
'category_slug' => NULL, | |
'sort' => 'DESC', | |
'order_by' => 'start_date', | |
), | |
$args, | |
'espresso_legacy_events' | |
); | |
$loop = new EventEspresso\core\domain\services\wp_queries\EventListQuery( $args ); | |
$big = 999999999; // need an unlikely integer | |
$pagination = paginate_links( array( | |
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), | |
'format' => '?paged=%#%', | |
'current' => max( 1, get_query_var('paged') ), | |
'total' => $loop->max_num_pages, | |
'show_all' => TRUE, | |
'end_size' => 10, | |
'mid_size' => 6, | |
'prev_next' => TRUE, | |
'prev_text' => '‹ PREV', | |
'next_text' => 'NEXT ›', | |
'type' => 'plain', | |
'add_args' => FALSE, | |
'add_fragment' => '' | |
)); | |
$output = '<div class="ui-widget">'; | |
$output .= '<article class="ee-event archived">'; | |
if( $loop->have_posts() ) { | |
// loop through posts | |
while ( $loop->have_posts() ) : $loop->the_post(); | |
global $post; | |
$event = EEH_Event_View::get_event(); | |
$output .= '<h3 style="margin-bottom:0;padding-left: 1rem;" class="ui-widget-header ui-corner-top event-title"><a href="' . get_the_permalink() . '">' . get_the_title() . '</a></h3>'; | |
$output .= '<div style="padding:1rem" class="ui-widget-content ui-corner-bottom event-items">'; | |
$output .= '<p class="event-time"><strong>Date and Time:</strong> <span class="start-date">' . espresso_next_upcoming_datetime('', '', $post->ID, false ) . '</span></p>'; | |
if ( $event instanceof EE_Event ) { | |
if ( ! $event->is_sold_out() && $event->is_upcoming() ) { | |
// grab array of EE_Ticket objects for event | |
$tickets = EEH_Event_View::event_tickets_available( $post->ID ); | |
// grab first ticket from array | |
$ticket = reset( $tickets ); | |
//check if the ticket is free, set the display to 'Free' | |
if ( $ticket instanceof EE_Ticket ) { | |
$ticket_price = $ticket->pretty_price(); | |
$ticket_price_data_value = $ticket->price(); | |
$ticket_price = $ticket_price_data_value == 0 ? 'Free' : $ticket_price; | |
$output .= '<p class="price">'; | |
$output .= '<strong>Price:</strong> '. $ticket_price . '</p>'; | |
} | |
$output .= '<p class="spaces-available">'; | |
$output .= '<strong>Available Spaces:</strong> '; | |
$output .= $event->spaces_remaining_for_sale(); | |
$output .= '</p>'; | |
$output .= '<p><a class="ui-button ui-button-big ui-priority-primary ui-state-default ui-state-hover ui-state-focus ui-corner-all" href="' . get_the_permalink() . '">Register</a></p>'; | |
} | |
} | |
$output .= '</div>'; | |
endwhile; | |
} | |
$output .= '</article>'; | |
// pagination links | |
$output .= ! empty( $pagination ) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : ''; | |
$output .= '</div>'; | |
wp_reset_postdata(); | |
return $output; | |
} | |
add_shortcode('espresso_legacy_events', 'my_ee_legacy_events_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment