|
<?php |
|
/** |
|
* List view nav template (making use of alternative pagination functions) |
|
* |
|
* This template isn't really the proper place for the two template definitions included |
|
* at the top, but they could easily be moved to a more suitable location. They've been |
|
* included in this file for no reason other than ease of demonstrating and sharing a |
|
* workaround. |
|
*/ |
|
defined( 'ABSPATH' ) or exit( '-1' ); |
|
|
|
|
|
if ( ! function_exists( 'tribe_are_there_previous_events' ) ) { |
|
/** |
|
* Try to determine if there are previous events we need to link to. |
|
* |
|
* @return bool |
|
*/ |
|
function tribe_are_there_previous_events() { |
|
global $wp_query; |
|
|
|
$upcoming = tribe_is_upcoming(); |
|
$past = ! $upcoming; |
|
$cur_page = (int) $wp_query->get( 'paged' ); |
|
$max_pages = (int) $wp_query->max_num_pages; |
|
$page_1 = 0 === $cur_page || 1 === $cur_page; |
|
|
|
// Simple tests based on pagination properties |
|
if ( $upcoming && $cur_page > 1 ) return true; |
|
if ( $past && $cur_page < $max_pages ) return true; |
|
|
|
// Test for past events (on first page of upcoming list only) |
|
if ( $upcoming && $page_1 ) { |
|
$args = (array) $wp_query->query; |
|
$args['eventDisplay'] = 'past'; |
|
$args['no_paging'] = true; |
|
$args['no_found_rows'] = true; |
|
$args['posts_per_page'] = 1; |
|
|
|
$past_events = tribe_get_events( $args ); |
|
return ( count( $past_events ) >= 1 ); |
|
} |
|
|
|
// Undetermined |
|
return false; |
|
} |
|
} |
|
|
|
if ( ! function_exists( 'tribe_are_there_more_events' ) ) { |
|
/** |
|
* Try to determine if there are more events to page forward into. |
|
* |
|
* @return bool |
|
*/ |
|
function tribe_are_there_more_events() { |
|
global $wp_query; |
|
|
|
$upcoming = tribe_is_upcoming(); |
|
$past = ! $upcoming; |
|
$cur_page = (int) $wp_query->get( 'paged' ); |
|
$max_pages = (int) $wp_query->max_num_pages; |
|
$page_1 = 0 === $cur_page || 1 === $cur_page; |
|
|
|
// Simple tests based on pagination properties |
|
if ( $upcoming && $cur_page < $max_pages ) return true; |
|
if ( $past && $cur_page > 1 ) return true; |
|
|
|
// Test for future events (on first page of the past events list only) |
|
if ( $past && $page_1 ) { |
|
$args = (array) $wp_query->query; |
|
$args['eventDisplay'] = 'list'; |
|
$args['no_paging'] = true; |
|
$args['no_found_rows'] = true; |
|
$args['posts_per_page'] = 1; |
|
|
|
$upcoming_events = tribe_get_events( $args ); |
|
return ( count( $upcoming_events ) >= 1 ); |
|
} |
|
|
|
// Undetermined |
|
return false; |
|
} |
|
} |
|
?> |
|
|
|
<h3 class="tribe-events-visuallyhidden"><?php _e( 'Events List Navigation', 'tribe-events-calendar' ) ?></h3> |
|
<ul class="tribe-events-sub-nav"> |
|
<!-- Left Navigation --> |
|
|
|
<?php if ( tribe_are_there_previous_events() ) : ?> |
|
<li class="<?php echo tribe_left_navigation_classes(); ?>"> |
|
<a href="<?php echo tribe_get_listview_link() ?>" rel="prev"><?php _e( '<span>«</span> Previous Events', 'tribe-events-calendar' ) ?></a> |
|
</li><!-- .tribe-events-nav-left --> |
|
<?php endif; ?> |
|
|
|
<!-- Right Navigation --> |
|
<?php if ( function_exists( 'tribe_are_there_more_events' ) && tribe_are_there_more_events() ) : ?> |
|
<li class="<?php echo tribe_right_navigation_classes(); ?>"> |
|
<a href="<?php echo tribe_get_listview_link() ?>" rel="next"><?php _e( 'Next Events <span>»</span>', 'tribe-events-calendar' ) ?></a> |
|
</li><!-- .tribe-events-nav-right --> |
|
<?php endif; ?> |
|
</ul> |