【发布时间】:2020-08-08 12:48:49
【问题描述】:
自定义我的archive-product.php。如何在自定义循环中仅显示特定类别中的产品? This similar question,没有解决我的问题。我尝试single_cat_title() 根据this 问题获取当前类别,但出现错误。我想我需要基于此documentation 使用get_queried_object(),但我不断收到错误。
我试过了:
<?php
$category = single_cat_title('', false); // this returns your current category ?>
<?php
// Setup your custom query
$args = array(
'post_type' => 'product',
'product_cat' => $category,
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php the_post_thumbnail(); ?>
<br>
<?php endwhile; wp_reset_query(); // Remember to reset ?>
我也试过了:
`$term_name = get_queried_object()->name;`
// Setup your custom query
$args = array(
'post_type' => 'product',
'product_cat' => $term_name, );
【问题讨论】:
标签: php wordpress loops woocommerce taxonomy-terms