I'm looking (without having to copy the whole code) that when the child page has child pages of it's own that it wil not show those child pages but still the parrent page 2 levels up. i played with it but in my opinion i have to copy the whole code, change the level setting, and give a different shortcode name.
function wpb_list_child_pages_popup()
{
// Define our $string variable
$string = '';
// Make sure this is a page
if ( !is_page() )
return $string;
$post = $GLOBALS['wp_the_query']->get_queried_object();
// Make sure the current page is not top level
if ( 0 === (int) $post->post_parent ) {
$parent = $post->ID;
} else {
$ancestors = get_ancestors( $post->ID, $post->post_type );
// Check if $ancestors have at least two key/value pairs
if ( 1 == count( $ancestors ) ) {
$parent = $post->post_parent;
} else {
$parent = $ancestors[1]; // Gets the parent two levels higher
}
}
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $parent . '&echo=0' );
$string .= '<ul id="child-menu">' . $childpages . '</ul>';
return $string;
}
add_shortcode('wpb_childpages_popup', 'wpb_list_child_pages_popup');
Code - Thanks to Pieter Goosen