How to.....?
How to display category hierarchy in WordPress
<ul>
<?php $categoryterm = get_terms("taxonomy-name", array("orderby" => "slug", "parent" => 0)); ?>
<?php foreach($categoryterm as $key => $cateterm) : ?>
<li>
<?php echo $cateterm->name; ?>
<?php $childterms = get_terms("taxonomy-name", array("orderby" => "slug", "parent" => $cateterm->term_id)); ?>
<?php if($childterms) : ?>
<ul>
<?php foreach($childterms as $key => $childterm) : ?>
<li><?php echo $childterm->name; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<ul>
<?php $categoryterm = get_terms("taxonomy-name", array("orderby" => "slug", "parent" => 0)); ?>
<?php foreach($categoryterm as $key => $cateterm) : ?>
<li>
<?php echo $cateterm->name; ?>
<?php $childterms = get_terms("taxonomy-name", array("orderby" => "slug", "parent" => $cateterm->term_id)); ?>
<?php if($childterms) : ?>
<ul>
<?php foreach($childterms as $key => $childterm) : ?>
<li><?php echo $childterm->name; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
Comments