Custom Menus are great for sitewide menus, but what if you only want to list a section’s subpages?
In the screenshot above, you’ll see the Plays dropdown lists three subpages. And on the right side, those same subpages are listed because we’re currently in the Plays section.
There’s a few popular approaches:
- Use wp_list_pages() to dynamically list all subpages to the current section. The downside here is you can’t easily hide items from this list, and you have to keep the page order in sync with the custom menu’s page order (so they appear in the same order). You also can’t provide custom lables for menu items. In the above example, “Current Season” is really a page called “2011-2012 Season”, and they’ll have older seasons they do not want displayed in this menu.
- Create a custom menu for each section. It’s a lot of work maintaining all these menus, and the end user can’t easily add a new section to the site since someone will need to create a menu for that section.
Assuming your main menu has all your site’s sections and their desired subpages, we can use
wp_get_nav_menu_items() to pull only the relevant subpages.