I’m over 2 hours trying many functions (wp_list_pages, get_pages, wp_nav_menu) and several functions but can’t resolve this thing out.
I have created pages that are THREE level deep:
PAGE level1
SUBPAGE level2
SUBPAGE level3
and I need to display a separate menu for each of them like:
MENU1 (all top-level pages)
MENU2 (all sub-pages of CURRENT top level page)
MENU3 (all sub pages of current item from MENU2)
it should not be that complicated for a CMS like WordPress but I think I’m over-complicating possible solutions.
Do you have some suggestions on possible ways to achieve that?
Thanks.
First of all you have to define accordance between menu items and pages. I can’t define this accordance from your question. What if you have two level2 subpages and two menu2 items? Which menu item belongs to which subpage?
Then the process is trivial. You can get all menu items
And check
menu_item_parent
field to found parent itemsIf you are using the the WordPress Function
register_nav_menus()
, it should be fairly simple.In your functions.php file you’ll need to register 3 separate menu’s, something like this:
With the menu’s now registered you just need to place them where they go in your theme files like so:
The First Menu (maybe in the header.php file)
The Second Menu (maybe in the sidebar.php file)
The Third Menu (maybe in the footer.php file)
The final step is to go to Appearance>Menu’s and create the 3 menu’s, name them and choose the pages that will go with them from within the Admin Menu Settings.