/* shorcode for menu [wpb_childpages]
Show children (1 level), if no children show sibbings (unless top level page)
*/
function wpb_list_child_pages() {
global $post;
$children = get_pages( array( 'child_of' => $post->ID ) );
if ( is_page() && count( $children ) > 0 ) {
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0&depth=1' ); // shows children
} else {
if ($post->post_parent == 0) { // $post->post_parent = 0 for top level (no parents) - don't show other top level pages!
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0&include=' . $post->ID ); // shows just this page
} else {
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' ); // shows siblings
}
}
if ( $childpages ) {
$string = '
- ' . $childpages . '
';
}
return $string;
}
add_shortcode('wpb_childpages', 'wpb_list_child_pages');