解决WordPress所有分页显示内容一样的方法
概述
在WordPress主题开发的时候我们常常需要把内容列表分页,比如说首页的文章数超过10条自动分页。
但有的时候会遇到无论点击哪页都只显示第一页内容的情况,碰到这种情况是因为使用了自定义查询(The Query),而查询内没有传入页码,所以想要真正实现内容分页,我们需要在The Query内容查询中传入页码参数。
实现方法
下面以一个默认的自定义查询为例,说明怎么解决因为The Query查询导致分页失效的方法。
< ?php
//获取页码
$paged = get_query_var('paged');
//查询参数
$args = array(
'posts_per_page' => 5, //显示5条内容
'paged' => $paged //按页码查询
);
query_posts($args);
//主循环
if ( have_posts() ) : while ( have_posts() ) : the_post();
..
endwhile; else:
..
endif;
//清理查询
wp_reset_query();
?>
2014.06.06更新:
有的同学用了这段代码非也以后文章显示错误,那是因为query_posts重置了查询,
解决方法在下面。
在查询条件里面加上:’cat’=>$cat,
就可以了。
WordPress无法显示留言表情的问题 Windows中AT命令与计划任务的区别
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://www.binance.info/register?ref=IXBIAFVY
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.