我在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'。謝謝 –