How do I add nested categories to drop-down menu in twenty-eleven?

I know how to do it by writing a separate ul/li css for wp_list_categories, but I find menus of “twenty eleven” already well designed and flexible, so I`d like to use them.
Custom menus, when I have to add subcategories manually, are not a solution, sinse I will allow my users to create new categories. What would you do?

Related posts

Leave a Reply

1 comment

  1. As a purely theory example, this is how I would approach the problem:

    $cats = get_categories();
    echo '<ul>';
    foreach($cats as $cat) {
        echo'<li>'.$cat->name;
        if($cat->parent != 0) {
           $subcats = get_category('child_of='.$cat->cat_ID;
           echo '<ul>';
           foreach($subcats as $subcat){
            echo '<li>'.$subcat->name.'</li>';
           }
        }
        echo '</li>';
    }
    echo '</ul>';
    

    I don’t expect that to work fully as I coded it there based of this codex entry but I am fairly certain that my theory is correct. I may have the $cat->parent backwards though…