Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way that I can list all the terms within a custom taxonomy in an unordered list and wrap all child terms in another unordered list?

For example;

<ul class="menu">

    <li><a href="#">Parent 1</a></li>
    <li>
        <a href="#">Parent 2</a>

        <ul class="sub-menu">

            <li><a href="#">Child of Parent 2</a></li>
            <li><a href="#">Child of Parent 2</a></li>
            <li><a href="#">Child of Parent 2</a></li>

        </ul>

    </li>
    <li><a href="#">Parent 3</a></li>

</ul>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can take a look at the Wordpress function wp_list_categories(). If you want to display all the terms within a given custom taxonomy you can for example use:

<?php 
$args = array(
  'taxonomy'     => 'my_custom_taxonomy_slug',
  'orderby'      => 'name',
  'hide_empty'   => 0,
  'title_li'     => '',
  'hierarchical' => 1,
  'walker'       => null,
);
?>
<ul class="menu">
<?php wp_list_categories( $args ); ?>
</ul>

If you need to adjust the html structure, you can use a custom walker that extends either Walker_Category or Walker.

You can read more about it here in the Codex:

http://codex.wordpress.org/Template_Tags/wp_list_categories

share|improve this answer
    
I didn't even need to add a walker, child categories are already contained in a ul! Thanks for steering me in the right direction! –  Dean Elliott Mar 27 '13 at 20:46
    
you're welcome, good luck with your project. –  birgire Mar 27 '13 at 20:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.