Created
January 8, 2012 22:19
-
-
Save jkudish/1579916 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<h1>Upcoming events:</h1> | |
<?php global $post; | |
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
$upcoming = tribe_get_events( array('eventDisplay'=>'past', 'posts_per_page'=>1,'paged' => get_query_var('page')) ); | |
foreach($upcoming as $post) : setup_postdata($post);?> | |
<div class="single-event"> | |
<div class="title"><a href="<?php the_permalink() ?>" rel="bookmark"> | |
<?php the_title(); ?> | |
</a> </div> | |
<?php endforeach; ?> | |
<?php if(function_exists('wp_pagenavi')) { // if PageNavi is activated ?> | |
<?php wp_pagenavi(); } | |
/** | |
* above is the original untouched code | |
* below is the better code (and it works!) | |
* the main difference is the use of WP_Query instead of tribe_get_events | |
* doing so is more efficient and ensures compatibility with WPPageNavi | |
* @see @link http://scribu.net/wordpress/wp-pagenavi/wpn-2-74.html for more details | |
*/ | |
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; | |
$upcoming = new WP_Query(); | |
$upcoming->query( array('post_type'=> 'tribe_events', 'eventDisplay' => 'past', 'posts_per_page' => 1, 'paged' => $paged) ); | |
if ($upcoming->have_posts()) : | |
while ($upcoming->have_posts()) : | |
$upcoming->the_post(); | |
?> | |
<div class="single-event"> | |
<div class="title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></div> | |
<?php | |
endwhile; | |
wp_pagenavi( array( 'query' => $upcoming ) ); | |
endif; | |
wp_reset_query(); | |
?> |
Depends on what you are trying to do with it. In this case, the user wanted to display past events.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't it be 'eventDisplay' => 'upcoming' for upcoming events instead of 'past'?