我有如下类别模式:
父母
当我单击“父级存档”页面时,有什么方法可以分别显示所有子级产品及其类别,但父级除外。我已经尝试了很多代码,但是它也给出了父类别和产品,但我只需要它是孩子。这是代码:-
foreach( get_terms( array( 'taxonomy' => 'product_cat' ) ) as $category ) :
$products_loop = new WP_Query( array(
'post_type' => 'product',
'showposts' => -1,
'hierarchical' => 1,
'depth' => 1,
'parent' => 0,
'tax_query' => array_merge( array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'terms' => array( $category->term_id ),
'field' => 'term_id'
)
), WC()->query->get_tax_query() ),
'meta_query' => array_merge( array(
// You can optionally add extra meta queries here
), WC()->query->get_meta_query() )
) );
?>
<h2 class="category-title"><?php echo $category->name; ?></h2>
<?php
while ( $products_loop->have_posts() ) {
$products_loop->the_post();
do_action( 'woocommerce_shop_loop' );
// wc_get_template_part( 'content', 'product' );
}
wp_reset_postdata(); ?>