I have added a post category to a custom menu through Admin. But when it shows, it just shows the category name, and does not show the posts inside the category. Is there a way to add an args; that the children post pages will also show with the category title in the menu?

This is my current function:

function wp_nav_links() {   
        'menu' => 'nav_links',
        'theme_location' => 'nav_links', 
        'container_class' => 'nav-links clearfix', 
        'fallback_cb' => 'nav_links_fallback'
  • wp_nav_menu accepts 'walker' => new My_Custom_Menu_Walker argument, which is where you create a new instance of your walker class. :) – Eric Holmes Feb 10 '14 at 14:26

If you created a menu, you would have to drag in those pages, as the basic Walker_Nav_Menu class does not pull subchildren into it. If this is your desired effect, you could created a custom Walker, essentially duplicate the start_el() function of Walker_Nav_Menu, and perform a check on $item->type to see if you are dealing with a Category - then create your submenu manually.

  • sounds about right. Not sure I understand all this yet. Ill look into it. Thanks for now. – Jon Feb 10 '14 at 14:17
  • No problem - a Walker is essentially something you hand an array of $items (whether it be posts, menu objects, terms, etc.) and it spits out the listing structure in HTML. start_el (element) creates most of the <li> structure element, start_lvl creates the submenu <ul> tag, and 'end_lvl'/'end_el` close the tags. Hence why start_el is where all the action happens :) – Eric Holmes Feb 10 '14 at 14:23
  • from what I read I add 'walker' => new fn_walker() to my array, and add to functions file something like - class fn_walker extends Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) etc? – Jon Feb 10 '14 at 14:33
  • Exactly! start_el is the real breadwinner as far as Walkers go - it's where the magic happens. – Eric Holmes Feb 10 '14 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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