2 回答
TA贡献1998条经验 获得超6个赞
您可以使用get_term_children()
来自产品类别术语 Id 的WordPress 专用功能:
$child_terms_ids = get_term_children( $term_id, 'product_cat' );
它返回一组子项 Id。
对于产品类别存档页面,您可以使用:
// get the current product category term ID
if ( is_product_category() ) {
$term_id = (int) get_queried_object_id();
}
if ( term_exists( $term_id, 'product_cat' ) ) {
$child_terms_ids = get_term_children( $term_id, 'product_cat' );
// Loop through child terms Ids
foreach ( $child_terms_ids as $child_term_id ) {
$child_term = get_term_by( 'term_id', $child_term_id, 'product_cat' );
// The term name
$child_name = $child_term->name;
// The term link
$child_link = get_term_link( $child_term, 'product_cat' );
}
}
- 2 回答
- 0 关注
- 232 浏览
添加回答
举报