试着弄清楚如何检查Woocommerce类别是否为父类别 .
我有一个类别和一个子类别,在我的Woocommerce模板中,有两个单独的布局HTML . 1表示父类,1表示子类 .
我目前正在使用这个:
if ( is_product_category( 'main-category' ) ) { ?>
但如果可以在不手动输入所有父类别的情况下进行检查,则会更容易 .
还有,有没有办法从子类别或子类别产品页面链接到主要父类别页面?
How to get Parent Category with total Subcategory count?
<?php $category_object = get_queried_object(); $category_taxonomy = $category_object->taxonomy; $category_term_id = $category_object->term_id; $category_name = $category_object->name; $category_description = $category_object->description; $category_slug = $category_object->slug; $category_children = get_terms( $category_taxonomy, array( 'parent' => $category_term_id, 'hide_empty' => false ) ); $category_children_count = count($category_children); if($category_children_count>0) { //get Parent Category with Subcategory count } ?>
1 回答
How to get Parent Category with total Subcategory count?