[英]Wordpress taxonomy.php loop only showing 2 posts?
我在Wordpress的taxonomy.php
模板中使用以下代码遇到了一些麻烦。 该查询正在运行(即仅从该自定义分类法中提取帖子),但仅显示2个帖子(分类法中有4个)。
我使用$ args将其转换为标准循环的所有努力只是导致所有分类法的帖子都被拉到页面中。 我希望它就像添加posts_per_page => -1
一样简单,但这只会导致显示整个站点中的每个帖子。
据我从法典上了解到,分类页面默认情况下应该拉相关事件,而无需循环?
任何帮助,不胜感激!
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(); ?>
更新
<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(); ?>
如果您有6个不同的分类法,那么将有6个不同的模板文件适当地显示那些分类法。 在您的情况下,您的模板将是taxonomy-topics.php
taxonomy-places.php
taxonomy-dates.php
taxonomy-interviewee.php
taxonomy-period.php
和taxonomy-az.php
这样,一旦创建了这些模板,您的模板就会显示适当的帖子。 为此,可以使用posts_per_page
参数,也可以访问此页面以更好地了解如何获取帖子WP_Query Codex页面希望到现在为止有意义
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.