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 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?

share|improve this question
    
Maybe this two links can help to find an answer... Looks like extending the Category Walker is the way to go. –  brasofilo May 13 '12 at 22:04

1 Answer 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...

share|improve this answer
    
If I get it right, this solution replaces the convenient menus system, instead of adding categories to it? I have used something like that, and I have used plugins that do it. But all these options mean killing current flexibility of menus, so if you want to add a page or link or anything later, you have to code again, instead of just editing custom menus in backend. –  Justinas Dūdėnas May 23 '12 at 6:02
    
If you want to add the link, you will need to do this echo <a href="' . get_category_link( $category->term_id ).'">'.$cat->name.'</a>'; I use code similar to this on one of my sites to generate a category based menu. Just add css classes and she'll be right. –  Joshua May 23 '12 at 22:58
    
Yeah, this is very similar to my current solution. Thank you for efforts, but I guess you miss the point: to retain the comfort of controlling menus from backend. –  Justinas Dūdėnas May 24 '12 at 6:03
    
For pages and so forth? there is an argument you can post to the $args array that orders by the menu tab. –  Joshua May 24 '12 at 22:41

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.