Creating a submenu for every parent page in WordPress

What I have is a very deep menu structure in WordPress, 5 levels deep in some pages. What I need is a menu for every parent above the current page. So for example if I am here:

Main / Sub / SubSub / SubSubSub I want to see, above each other:

Read More
  • Menu for all main items
  • Menu for all items in Sub
  • Menu for all items in SubSub, including SubSubSub

I am using the wp_list_pages function like this:

<?php
  if ( $post->post_parent ) {

$args = array(
  'child_of'    => $post->ID,
  'depth'       => 1,
  'sort_column' => 'post_date',
  'sort_order'  => 'DESC',
  'title_li'    => ''
);
echo '<nav id="subnav"><ul>';
  wp_list_pages( $args );
echo '</ul></nav>';

} ?>

But I cannot tell if I am at lvl 2 or below. I found the ancestor menu (always shown) with this bit:

'child_of' => get_post_top_ancestor_id()

But I cannot get it to list one menu for every other parent that is not the topmost ancestor. I tried modifying this code here:
https://wordpress.stackexchange.com/questions/15141/list-wordpress-custom-menus-active-parent-levels-children-as-separate-menu

and looping through all parents like here:
http://wordpress.org/support/topic/get-and-display-parent-pages-of-a-menu

Main problem is I am not much of a PHP programmer so creating my own functions is not really an option. Any help is much appreciated

Related posts

Leave a Reply

1 comment

  1. Almost there, I still nee to loop through $howdeep > 2 and find the correct level to show… If someone knows how to do it…

    <?php
    
    $id = 0;
    $thispost = get_post($id);
    $howdeep = 1;
    $parentID = $thispost->post_parent;
    while( $parentID != 0 ) {
    $parent = get_post($parentID);
    $howdeep++;
    $parentID = $parent->post_parent;
    }
    
    if ( $howdeep == 2 ) {
    
    $args = array(
        'child_of'      => $post->ID,
        'depth'         => 1,
        'sort_column'   => 'post_date',
        'sort_order'    => 'DESC',
        'title_li'      => ''
    );
    echo '<nav id="subsubnav"><ul>';
        wp_list_pages( $args );
    echo '</ul></nav>';
    
    } else if ( $howdeep == 3 ) {
    
    $args = array(
        'child_of'      => $post->post_parent,
        'depth'         => 1,
        'sort_column'   => 'post_date',
        'sort_order'    => 'DESC',
        'title_li'      => ''
    );
    echo '<nav id="subsubnav"><ul>';
        wp_list_pages( $args );
    echo '</ul></nav>';
    
    } ?>