我在Wordpress的taxonomy.php
模板中遇到以下代码存在一些问题。该查询正在工作(即仅从该自定义分类中抽取帖子),但它只显示2个帖子(4个在分类中)。WordPress的taxonomy.php循环只显示2个帖子?
我所有使用$ args将其转换为标准循环的努力只会导致来自所有分类法的帖子被拉入页面。我希望它可以像添加posts_per_page => -1
一样简单,但这只会导致整个站点中的每个帖子都显示出来。
正如我从codex中了解到的,分类标准页面应该默认提取相关帖子,而不需要循环?
任何帮助非常感谢!
taxonomy.php
<?php get_header(); ?>
<main>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<figure>
<?php if (has_post_thumbnail()) {
the_post_thumbnail();
} ?>
<figcaption>
<h4><?php the_title(); ?></h4>
<h5><?php the_excerpt(); ?></h5>
</figcaption>
</figure>
<?php endwhile; ?>
<?php endif; ?>
</main>
<?php get_footer(); ?>
UPDATE
<main>
<?php
$args = array(
'posts_per_page' => -1
);
$the_query = new WP_Query($args); ?>
<?php if ($the_query->have_posts()) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<figure>
<?php if (has_post_thumbnail()) {
the_post_thumbnail();
} ?>
<figcaption>
<h4><?php the_title(); ?></h4>
<h5><?php the_excerpt(); ?></h5>
</figcaption>
</figure>
<?php endwhile; ?>
<?php endif; ?>
</main>
<?php get_footer(); ?>
你会提供您的自定义分类的名字,这样我可以为您提供的代码,以显示正确的职位有关该分类? – laraib
嗨@laraib,我实际上有6个分类法,每个都有多个'术语'。当用户通过点击“期限”从索引页面点击时使用分类页面 - 然后应该在该期限内显示x个帖子的形式。合理?我的6个分类标准是:'主题','地点','日期','受访者','时期'和'a-z'。谢谢 –