WordPress翻页无效解决方案

状况:页面是翻过去了,地址也变了,就是内容没变

猜测:使用query_posts()函数调用任何内容都很方便,
但是对分页导航或者默认的翻页不起作用,
包括用这个函数调用特定分类下的文章或者排除一个或几个分类下的文章时。
如果是用get_posts()函数效果一如query_posts()函数但是不会形成分页

解释:使用query_posts()函数调用文章,query_posts()函数会关闭对分页功能的呼叫(If you manipulate query_posts() directly, it turns off paging. Sorry.

解决办法:把内容调用代码

<?php query_posts(‘showposts=20&cat=11′); ?>

改为以下的代码:

<?php
$limit = get_option('posts_per_page');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('cat=10&showposts=' . $limit=10 . '&paged=' . $paged);
$wp_query->is_archive = true; $wp_query->is_home = false;
?>

其中limit=10可以自由设置,即每页显示的文章数,cat=10是调用分类的ID,我在自己的这个wordpress上已经测试成功。

3 条评论
  • Tom

    学习了666

    回复
  • I visited multiple websites but the audio feature for audio
    songs current at this web page is really fabulous.

    回复
  • Have you ever considered about including a little bit more than just
    your articles? I mean, what you say is valuable and all.
    Nevertheless think of if you added some great visuals or videos to give your posts more,
    “pop”! Your content is excellent but with images and videos,
    this site could certainly be one of the greatest
    in its field. Excellent blog!

    回复