Last active
July 21, 2019 22:40
-
-
Save joshfeck/61a9e21bbc9d4111fbdf to your computer and use it in GitHub Desktop.
Past event archives page template for EE4. This can be adapted to most WP themes. Prints a simple unordered one page list of expired events.
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 Events Only List | |
*/ | |
get_header(); ?> | |
<div id="primary" class="content-area"> | |
<main id="main" class="site-main" role="main"> | |
<div class="module"> | |
<ul class="past-event-list"> | |
<?php | |
$args = array( | |
'limit' => 100, | |
'show_expired' => TRUE, | |
'sort' => 'DESC', | |
'order_by' => 'start_date', | |
); | |
add_filter( 'posts_where', 'custom_posts_where_sql_for_only_expired' ); | |
$loop = new EventEspresso\core\domain\services\wp_queries\EventListQuery( $args ); | |
if( $loop->have_posts() ) { | |
// loop through posts | |
while ( $loop->have_posts() ) : $loop->the_post(); | |
?> | |
<li> | |
<a class="event-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a> | |
<span class="start-date"><?php espresso_event_date(); ?></span> | |
</li> | |
<?php | |
endwhile; | |
} | |
remove_filter( 'posts_where', 'custom_posts_where_sql_for_only_expired' ); | |
wp_reset_postdata(); | |
?> | |
</ul> | |
<?php // pagination links | |
$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' => '' | |
)); | |
echo ! empty( $pagination ) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : ''; | |
?> | |
</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
Nice!