Last active
June 6, 2017 18:20
-
-
Save joshfeck/56bc9e4a3683779fe90f to your computer and use it in GitHub Desktop.
Past event archives page template for EE4. This can be adapted to most WP themes. Allows for usage of EE4 template tags and includes WP pagination
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 | |
// alter the query to only the primary datetimes that ended before today | |
// adjust query as desired | |
// add this to your child theme's functions.php file or into a custom plugin | |
function custom_posts_where_sql_for_only_expired() { | |
return ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end < "' . current_time( 'mysql', TRUE ) . '" '; | |
} |
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 | |
/** | |
Template Name: Past event archives | |
*/ | |
// load in Event Espresso view helpers so event template tags can be used | |
EE_Registry::instance()->load_helper( 'Event_View' ); | |
EE_Registry::instance()->load_helper( 'Venue_View' ); | |
// call in the theme's header.php template | |
get_header(); ?> | |
<!-- theme markup --> | |
<div id="primary" class="content-area"> | |
<main id="main" class="site-main" role="main"> | |
<div class="module"> | |
<?php // query parameters | |
$args = array( | |
'limit' => 10, // 10 per page | |
'show_expired' => TRUE, // want to include expired events | |
'sort' => 'ASC', // start with the first event ever | |
); | |
// apply the filter to limit primary datetimes to before today | |
add_filter( 'posts_where', 'custom_posts_where_sql_for_only_expired' ); | |
// the query | |
global $wp_query; | |
$wp_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery( $args ); | |
// the loop | |
if( have_posts() ) { | |
// loop through posts | |
while ( have_posts() ) : the_post(); | |
// Include the post TYPE-specific template for the content. | |
espresso_get_template_part( 'content', 'espresso_events' ); | |
endwhile; | |
// Previous/next page navigation. ?> | |
<div class="pagination"> | |
<?php $big = 999999999; // need an unlikely integer | |
echo paginate_links( array( | |
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), | |
'format' => '?paged=%#%', | |
'current' => max( 1, get_query_var('paged') ), | |
'total' => $wp_query->max_num_pages | |
) ); ?> | |
</div> | |
<?php | |
} | |
remove_filter( 'posts_where', 'custom_posts_where_sql_for_only_expired' ); | |
wp_reset_postdata(); | |
?> | |
</div><!-- #module --> | |
</main><!-- #main --> | |
</div><!-- #primary --> | |
<?php get_sidebar(); ?> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment