[英]How to show Product Subcategories on categories page
我想在我的woocomerce wordpress網站上單擊產品類別,然后先顯示子類別,然后再顯示產品...
這樣的事情。
<?php if (is_category()) {
$this_category = get_category($cat);
}
?>
<?php
if($this_category->category_parent)
$this_category = wp_list_categories('orderby=id
&title_li=&use_desc_for_title=1&child_of='.$this_category->category_parent.
"&echo=0"); else
$this_category = wp_list_categories('orderby=id&depth=1
&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID.
"&echo=0");
if ($this_category) { ?>
<ul>
<?php echo $this_category; ?>
</ul>
<?php } ?>
將此添加到主題的“ functions.php”中。
function show_product_subcategories( $args = array() ) {
if(!is_shop()) //not shop page
{
$parentid = get_queried_object_id();
$args = array(
'parent' => $parentid,
'hide_empty' => false,
);
$terms = get_terms( 'product_cat', $args );
if ( $terms ) {
echo '<div class="sub_categories">
<ul class="product-cats cat_products_list">';
foreach ( $terms as $category ) {
wc_get_template('content-product_cat.php',array('category'=>$category));
}
echo '</ul><div class="clearfix"></div></div>';
}
}
}
add_action( 'woocommerce_before_shop_loop', 'show_product_subcategories', 50 );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.