Support » Plugins » Hacks » Get and display parent pages of a menu.

  • I have a horizontal dropdown menu on top, with 4 custom links as parent menu items and some child pages underneath one of each.

    In the side-bar I want to show the user (because the main horizontal menu is a dropdown menu) a second navigation list with on top the title of the current (one of the four) main parent menu items and underneath all the child pages of that specific parent menu item.

    With wp_list_pages() it was pretty easy but I have no clue of fixing this thing with the new wp_nav_menu().

    I used this link to get me started about making a custom walker.

    But I have no idea to move further.

    Anybody some ideas or experience with this issue?


Viewing 5 replies - 1 through 5 (of 5 total)
  • With wp_list_pages I use a code like this underneath. Can something similair been made with wp_nav_menu()?

    $parent_title = get_the_title($post->post_parent);
    							$output = wp_list_pages('echo=0&depth=1&title_li=Top Level Pages&exclude=13,2' );
    							if (is_page( )) {
      							$page = $post->ID;
      							if ($post->post_parent) {
        							$page = $post->post_parent;
      								$children=wp_list_pages( 'echo=0&child_of=' . $page . '&title_li=' );
      								if ($children) {
       								 $output = wp_list_pages ('echo=0&child_of=' . $page . '&title_li='.$parent_title.' ');
    								echo $output;

    Is anyone out there proposing the answer of same question written above. I am looking for the same

    I hope this question gets some replies. It would be great so see how to deal with wp_nav_menu() in this situation.

    Hi Guys,

    Maybe unrelated, but I had to try and locate the parent, then maybe someone else can figure out the listing bit. I just needed to link back to the parent if it was a page.

    // Traverse and locate the parent structure on the main menu
            // 2n = slow search
            $menuItems = wp_get_nav_menu_items('main-menu');
            foreach($menuItems as $menuItem) {
                if($menuItem->object_id == $post->ID && $menuItem->object == $post->post_type) {
                    $parentMenuId = $menuItem->menu_item_parent;
            foreach($menuItems as $menuItem) {
                if($menuItem->ID == $parentMenuId && $menuItem->object == 'page') {
                    $pageId = $menuItem->object_id;
                    $menuId = $menuItem->ID;
            // Link back up to the page
            $content = '<a href="' . get_page_link($pageId) . '">' . get_the_title($pageId) . '</a>';

    Not the nicest way, but it was just the quickest way without finding a nice API method. Theoretically someone else could contribute displaying the children thing once you have the $id. 🙂 cheers

    Thanks for your reply Cammanderson!
    Your code looks promising. I’ll look into it.


Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Get and display parent pages of a menu.’ is closed to new replies.