wordpress WP_QUERY自定义帖子类型分页不起作用

时间:2015-11-04 13:05:18

标签: wordpress pagination wp-query

我正试图在category.php页面上显示分页,这段代码如下:      

OrderDetail

分页不起作用(当我点击"较旧的帖子"我被重定向到主页),但当我强制这样的$ paged变量时     $ paged = 2;     ...... 它按预期显示第二页! 有人可以帮助我!

1 个答案:

答案 0 :(得分:0)

get_next_posts_link()通常指向较旧的条目(朝向集合的末尾),get_previous_posts_link()通常指向较新的条目(朝向集合的开头)。

实施例

$cat = wp_strip_all_tags( get_the_category_list());

$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;

$the_query = new WP_Query( array( 
    'post_type' => ‘post’,
    'orderby' => 'date',
    'category_name' => $cat,
    'order' => 'DESC',
    'paged' => $paged,
    'posts_per_page' => 2) 
);

//usage of the $the_query
while ( $the_query->have_posts() ) : $the_query->the_post();

// Do Something

endwhile; 

//pagination
get_next_posts_link('Older', $the_query->max_num_pages);
get_previous_posts_link( 'Newer', $the_query->max_num_pages);
相关问题