如何编辑category.php模板,以便显示特定类别的所有文章?
问题描述:
我在category.php模板简单wordpres类别环路后是这样的:如何编辑category.php模板,以便显示特定类别的所有文章?
<?php if (have_posts()) : while (have_posts()) : the_post(); $postid = get_the_ID();?>
如何更改后限制吗?因为现在我每个类别只能获得十个帖子。我为所有类别使用了一个模板。我是wordpres的新手,并试图制作我的第一个自定义模板:)
答
您可以更改后端每页的帖子数。设置 - >阅读。在那里你可以改变它的地方:“博客页面最多显示”。
答
就在你的论点
'posts_per_page' => -1
然后你做添加此。
还有一件事:你可以将默认设置从管理改为10以外的其他设置。转到WordPress管理 - 设置 - 阅读。有一个选项,如“博客页面最多显示”。输入你想要的默认文章数量。
它将改变设置的所有网页,但如果你想使这一变化仅适用于标签页,然后在你的情况,你可以更改环tag.php文件中的代码如下:
global $wp;
$s_array = array('posts_per_page' => -1); // Change to how many posts you want to display
$new_query = array_merge($s_array, (array)$wp->query_vars);
query_posts($new_query);
<?php
if (have_posts()) : while (have_posts()) : the_post(); ?>
<!-- Here I grab the image from the post with that tag -->
<?php endwhile; ?>
<?php wp_reset_query();?>
答
要显示你有每个职位是10.请参阅下面的代码覆盖它的默认显示类别模板的所有帖子:
$args = array('posts_per_page' => -1);
$the_query = new WP_Query($args);
while ($the_query->have_posts()) {
$the_query->the_post();
/** Your code here **/
}
显示所有的职位上,模板是不是一个好的做法,相反,我会推荐每页显示10篇文章并显示分页。