嗨,我想在 wordpress 中创建一个类别树,如下所示:
<ul>
<a href=""> PARENT1 </a>
<li><a href=""> CHILD 1-1</a></li>
<li><a href=""> CHILD 1-2</a></li>
.
.
.
</ul>
<ul>
<a href=""> PARENT2 </a>
<li><a href=""> CHILD 2-1</a></li>
<li><a href=""> CHILD 2-2</a></li>
.
.
.
</ul>
我想要以上述格式创建类别列表并仅显示有孩子的类别并隐藏没有孩子的类别
我试过这样的东西,但它没有给我我想要的东西
<?php $args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'category',
'pad_counts' => false
);
$cats = get_categories( $args );
foreach( $cats as $cat) {
if($cat->parent == 0) {
$head = $cat->name;
$cat_id = $cat->term_id;
}
echo "<a href=''>" . $head . "</a>";
wp_list_cats("sort_column=NAME&optioncount=0&hierarchical=1&hide_empty=0&child_of={$cat_id}");
}
?>