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.

i want to display my categories to a post like a list. i have this (parent- and child-) categories:

- Sports
    - Football
    - Basketball
- Toys
    - Dolls
    - Lego
- Books

for example one post is archived to the categories "Sports", "Football", and "Books" i want to output the categories like this:

<ul>
    <li><a href="#">Sports</a>
        <ul class="children">
             <li><a href="#">Football</a></li>
        </ul>
    </li>
    <li><a href="#">Books</a></li>
</ul>

…as you can see, the hierarchical order by parent->child is important!

thanks, Jochen

share|improve this question
add comment

1 Answer

Using wp_list_categories

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

Something like this should give you what you want

$args = array(
    'hierarchical' => true,
    'hide_empty' => 0,
    'title_li' => ''
    );

wp_list_categories($args);
share|improve this answer
    
unfortunately not… it gives me ALL the categories from the system (like using it in the sidebar). but i want to have just the categories displayed which are assigned to the shown post!!! like using "the_category" in single.php! i hope you know what i mean... –  Jochen Schmidt Feb 25 '13 at 15:50
add comment

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.