2 回答

TA貢獻1998條經(jīng)驗 獲得超6個贊
您可以使用get_term_children()
來自產(chǎn)品類別術語 Id 的WordPress 專用功能:
$child_terms_ids = get_term_children( $term_id, 'product_cat' );
它返回一組子項 Id。
對于產(chǎn)品類別存檔頁面,您可以使用:
// 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 關注
- 249 瀏覽
添加回答
舉報