我有代码,显示所有子类别。但我需要只显示第一级,而在第二级显示产品
1. Category
1.1 First-level
1.1.1 Second level
代码:
$second_level_cats = get_term_children($cat->term_id, $cat->taxonomy);
foreach ($second_level_cats as $second_level_cat_id) :
if(!get_term_children($cat_id, $cat->taxonomy)) :
$second_level_cat = get_term($second_level_cat_id, $cat->taxonomy);
endif;
endforeach;
答案 0 :(得分:0)
您可以使用以下代码获取父猫:
<?php
$cat_id = get_query_var('cat');
$args=array(
'parent' => $cat_id,
'hide_empty' => 0,
'orderby' => 'name',
'order' => 'ASC'
);