要仅显示指定的类别,您需要更改hide_empty 为真。
请查看修改后的代码:
$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>\';
请查看更新的代码:
$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>\';