2013-06-27 76 views
3

我最近有很多帮助创建即将发生的事件列表(请参阅此处Showing upcoming events (including todays event)?),因此使用WP Pagenavi的分页打破。分页显示所有其他页面上的第1页相同的帖子

目前,当您点击第2页时,它只显示与第一页相同的帖子。尽管该网址并真正改变页/ 2页/ 3等

我有这个在我functions.php文件:

function filter_where($where = '') { 
    $where .= " AND post_date >= '" . date("Y-m-d") . "'"; 
    return $where; 
} 

add_filter('posts_where', 'filter_where'); 

$query = new WP_Query(
    array(
     'post__not_in' => array(4269), 
     'paged' => get_query_var('paged'), 
     'post_type' => 'whatson', 
     'exclude' => '4269', 
     'post_status' => 'future,publish', 
     'posts_per_page' => 20, 
     'order' => 'ASC' 
    ) 
); 

remove_filter('posts_where', 'filter_where'); 

我环路则如下:

<?php while ($query->have_posts()) : $query->the_post(); ?> 
// content 
<?php endwhile; // end of the loop. ?> 
<?php if (function_exists('wp_pagenavi')) { wp_pagenavi(array('query' => $query)); } ?> 

回答

3

最后用解决了这个

<?php 
$wp_query = array(
     'post__not_in' => array(4269), 
     'paged' => get_query_var('paged'), 
     'post_type' => 'whatson', 
     'exclude' => '4269', 
     'posts_per_page' => 20, 
     'order' => 'ASC', 
     'orderby' => 'date', 
     'post_status' =>array('future','published')); 
query_posts($wp_query); 
?> 

<?php 
if ($wp_query->have_posts()) { 
    while ($wp_query->have_posts()) : $wp_query->the_post(); ?> 
     Content 
    <?php endwhile; // end of the loop. 
} ?> 

<?php if (function_exists('wp_pagenavi')) { wp_pagenavi(array('query' => $wp_query)); } ?> 
+0

顺便说一句。之所以不起作用,是因为在静态页面上输出帖子时,你必须使用'get_query_var('page')'而不是'get_query_var'''paged')' – n1te

+0

@ n1te不是,两者之间的改变没有任何区别。 – Rob

1

你想要它的特定职位或所有的人?如果你想一般分页可以使无插件分页链接使用这段代码:

<?php 
global $wp_query; 
$big = 999999999; // need an unlikely integer 
echo paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)), 
'format' => '?paged=%#%', 
'current' => max(1, get_query_var('paged')), 
'total' => $wp_query->max_num_pages 
)); 
?> 

只需将其添加到您的index.php或archives.php,看到奇迹发生了:)

+0

我想为所有的人。如果可能的话,我想尽力让它与我所拥有的一起工作。 – Rob

1

我不知道你的代码的其他部分发生了什么,但有一件事要做,那就是在你的new WP_Query之前使用wp_reset_query()来确保查询变量没有被修改。

function my_filter_where($where = '') { 
    global $wp_query; 
    if (is_array($wp_query->query_vars['post_status'])) { 

     if (in_array('future',$wp_query->query_vars['post_status'])) { 
     // posts today into the future 
     $where .= " AND post_date > '" . date('Y-m-d', strtotime('now')) . "'"; 
     } 
    } 
    return $where; 
} 
add_filter('posts_where', 'my_filter_where'); 

而且:

+0

我在几个不同的地方给了它一个去,但现在运气好。 – Rob

相关问题