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

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…

Leave a Comment