I am looking to display the number of child posts for a hierarchical parent post in a wordpress menu. So, I will be adding the parent post to the menu. Obviously I will have to go with a custom Walker but I am unsure where to begin.
ie:
Menu Item (8)
Menu Item (15)
Menu Item (7)
WordPress stores the parent/child menu items relation via custom field called
_menu_item_menu_item_parent
. Therefore you can query for the sub-menu items in the following way:This walker will add
<span class="submenus-count">(X)</span>
after all top-level links.You can call the menu like that:
wp_nav_menu(array('theme_location' => 'theme-location', 'container' => '', 'walker' => new add_child_numbers_walker()));
Since you said that you want to do a custom function to display your menus, here is a simple solution:
You can then display your menu like that: