I am trying to create a template for sub-category where I can display products under sub-category and in parent category page want to display only related sub-categories of the parent category. Can anyone suggest me with the example of code? how to start this.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Try the following:
if ( is_product_category() ) {
$terms = get_terms( array('taxonomy' => 'product_cat', 'parent' => get_queried_object_id() ) );
foreach ( $terms as $term ){
$term_link = get_term_link( $term, $taxonomy );
echo '<a class="ccats" href="'.$term_link.'"><span class="label">'.$term->name.'</span></a>';
}
}