【发布时间】:2015-07-17 14:12:43
【问题描述】:
我是 php 和 wordpress 的新手。
我将帖子类别用作一个简单的目录,并希望用户在点击一个类别时查看每个帖子,而不是对结果进行分页。
在主题附带的 Archive.php 中,我尝试过这样的事情:
/* Get the current category and increase the number of posts shown */
<?php
$category = $wp_query->get_queried_object()->slug;
query_posts('category_name=$category&showposts=100');
?>
<div id="content">
<?php if ( have_posts() ) : ?>
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div><!-- /content -->
但是,它不起作用。点击类别显示未找到任何帖子。
我确信有一种更好、更简单的方法可以做到这一点。
第二个问题是,将这种逻辑仅应用于我拥有的类别子集的好方法是什么?我想我可以创建一个类别数组并进行查询,但这似乎很笨拙。
非常感谢。
【问题讨论】:
-
您无需在存档页面上执行
query_posts()...默认查询已包含类别帖子。 -
好的,谢谢,我想我只是用它来更改查询以显示更多帖子,如果我手动输入类别名称来代替 $category 就会这样做。必须有更好的方法来增加显示的帖子数量(可能显示“全部”)。
标签: wordpress