任何人都可以解释我如何在类别存档页面中显示该类别中的产品编号,如类别1(10)
网址为http://www.example.com/product-category/category-1/
任何人都可以帮助我.............. 我试过这个,但它显示了网站的总产品。我只想要那个类别的产品
<h1><?php woocommerce_page_title();
global $woocommerce_loop;
do_action( 'woocommerce_before_subcategory', $category );
echo apply_filters( 'woocommerce_subcategory_count_html', ' <mark class="count">(' . $category->count . ')</mark>', $category );
?>
</h1>
答案 0 :(得分:2)
列出所有类别以及产品数量:
$terms = get_terms( 'product_cat' );
foreach( $terms as $term )
{
echo 'Product Category: '
. $term->name
. ' - Count: '
. $term->count;
}
如果您有类别ID:
$term = get_term( CAT_ID, 'product_cat' ); //Replace your category ID here
echo 'Product Category: '
. $term->name
. ' - Count: '
. $term->count;
答案 1 :(得分:2)
我能够解决这个问题
<h1><?php woocommerce_page_title();
global $wp_query;
// get the query object
$cat_obj = $wp_query->get_queried_object();
if($cat_obj) {
$category_name = $cat_obj->name;
$category_desc = $cat_obj->description;
$category_ID = $cat_obj->term_id;
}
$term = get_term( $category_ID, 'product_cat' );
echo '('. $term->count . ')';
?>
</h1>
将其放在&#34; archive-product.php&#34;
中