我设法做了更多的工作,并自己构建了答案。这是我需要的代码。
<?php
$parent_terms = get_terms(\'section\', \'orderby=name&hide_empty=0&parent=0\');
foreach ( $parent_terms as $parent_term ) { ?>
<div class="accordian open">
<div class="accordian-title module-gradient"><?php echo $parent_term->name; ?></div>
<?php
$get_parent = get_term_by(\'name\', $parent_term->name, \'section\');
$parent_id = $get_parent->term_id;
$child_terms = get_terms(\'section\', \'orderby=name&hide_empty=0&parent=\'.$parent_id);
if ( count($child_terms) > 0 ) { ?>
<div class="accordian-menu">
<?php foreach ( $child_terms as $child_term ) { ?>
<div class="accordian-item">
<?php echo $child_term->name; ?>
</div>
<?php } ?>
</div>
<?php } ?>
</div>
<?php } ?>