admin管理员组文章数量:1425815
Hi basically I have categori ID number (134) that has 2 child of that (red and blue). I selected the blue one. I want to display only the selected one (blue). But at the moment the show all subcategories (red and blue). Please help me here my code
$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'hide_empty' => 0,
'parent' => 134,
'taxonomy' => 'product_cat'
);
$subcats = get_categories($args);
echo '<ul class="wooc_sclist">';
foreach ($subcats as $sc) {
$link = get_term_link( $sc->slug, $sc->taxonomy );
echo '<li><a href="'. $link .'">'.$sc->name.'</a></li>';
}
echo '</ul>';
Here for single product page.
Hi basically I have categori ID number (134) that has 2 child of that (red and blue). I selected the blue one. I want to display only the selected one (blue). But at the moment the show all subcategories (red and blue). Please help me here my code
$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'hide_empty' => 0,
'parent' => 134,
'taxonomy' => 'product_cat'
);
$subcats = get_categories($args);
echo '<ul class="wooc_sclist">';
foreach ($subcats as $sc) {
$link = get_term_link( $sc->slug, $sc->taxonomy );
echo '<li><a href="'. $link .'">'.$sc->name.'</a></li>';
}
echo '</ul>';
Here for single product page.
Share Improve this question asked Jun 18, 2019 at 4:33 Wilda SagitaWilda Sagita 34 bronze badges 01 Answer
Reset to default 0To display only assigned category you need to change hide_empty to true.
Please see the modified code:
$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'hide_empty' => true,
'parent' => 134,
'taxonomy' => 'product_cat'
);
$subcats = get_categories($args);
echo '<ul class="wooc_sclist">';
foreach ($subcats as $sc) {
$link = get_term_link( $sc->slug, $sc->taxonomy );
echo '<li><a href="'. $link .'">'.$sc->name.'</a></li>';
}
echo '</ul>';
Please see the updated code:
$cats_list = get_the_terms ( get_the_ID() , 'product_cat' );
echo '<ul class="wooc_sclist">';
foreach ($cats_list as $cats) {
$link = get_term_link( $cats->slug, $cats->taxonomy );
echo '<li><a href="'. $link .'">'.$cats->name.'</a></li>';
}
echo '</ul>';
本文标签: phpShow subcategory name selected in specific category woocoommerce
版权声明:本文标题:php - Show subcategory name selected in specific category woocoommerce 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745385557a2656359.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论