Wordpress Can';你不能从分类中得到文章来展示吗?

Wordpress Can';你不能从分类中得到文章来展示吗?,wordpress,taxonomy,Wordpress,Taxonomy,我有一个叫做“产品”的wordpress分类法。我知道我的分类法的模板文件是taxonomy-product.php,但是,当我使用默认的wordpress post循环时,它会显示默认的“posts”分类法中的帖子,而不是我的自定义分类法“product” 我怎样才能解决这个问题? 这是我放在taxonomy-product.php中的代码 <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div

我有一个叫做“产品”的wordpress分类法。我知道我的分类法的模板文件是taxonomy-product.php,但是,当我使用默认的wordpress post循环时,它会显示默认的“posts”分类法中的帖子,而不是我的自定义分类法“product”

我怎样才能解决这个问题? 这是我放在taxonomy-product.php中的代码

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="product">
<?php the_post_thumbnail();?>
<h2 class="product-title">
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
</h2>
<a class="product-view" href="<?php the_permalink() ?>">View Product</a>
</div>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>


Carly,您的问题是没有在循环中包含要循环的分类法。试试这个:

<?php

$args = array( 'product' => 'example-product' );
$loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post();

<div class="product">

    <?php the_post_thumbnail();?>

    <h2 class="product-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

    <a class="product-view" href="<?php the_permalink() ?>">View Product</a>

</div>

<?php endwhile; else: ?>

<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>

endwhile;

?>

结束时; ?>