0

我一直在尝试在某个类别的页面中显示所有帖子。这是我到目前为止所做的:

<?php
$args = array(
             'category_name' => 'diy-tutorial',
             'post_type' => 'post',
             'posts_per_page' => 3
             //'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
             );
query_posts($args);
$x = 0;
while (have_posts()) : the_post(); ?>

它实际上是有效的,但它不会让我导航到类别的下一页例如,我在该类别中有 30 个帖子,所以我的代码每页会显示三个帖子,对吗?如果我更改每页显示的帖子数,则下一个>>链接不会显示得很好,它也不会工作......

如果您有其他显示方式,请告诉我。

4

2 回答 2

0

我相信您必须添加按钮并可能建立功能:阅读 Codex 朋友:https ://codex.wordpress.org/Pagination#Function_Reference

另外,我相信您的代码中注释掉的部分必须处于活动状态才能声明分页。

<nav class="wp-prev-next">
    <ul class="clearfix">
        <li class="prev-link"><?php next_posts_link(__('&laquo; Older Entries', "bonestheme")) ?></li>
        <li class="next-link"><?php previous_posts_link(__('Newer Entries &raquo;', "bonestheme")) ?></li>
    </ul>
</nav>
于 2013-08-07T01:34:05.333 回答
0

抱歉,我的 wordpress 有点生疏,但我喜欢获取帖子的方式是将查询字符串传递给 get_posts

$catID=get_cat_id('diy-tutorial');
$queryString="cat=".$catID."&numberposts=1000";
 global $post;
 //execute the query from the string 
 $myposts = get_posts($queryString);
//loop thru and do stuff
 foreach($myposts as $post) :
 setup_postdata($post);
the_post();
endforeach;

在此处查看法典:http: //codex.wordpress.org/Template_Tags/get_posts

于 2013-08-07T01:39:05.737 回答