Created
September 20, 2017 15:59
-
-
Save celticwebdesign/c91b2b3758be61dde4eb34158d57e713 to your computer and use it in GitHub Desktop.
If the page is a parent then show child page links, if the page does not page child pages, show pages links of parent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://wordpress.stackexchange.com/questions/35724/function-to-return-true-if-current-page-has-child-pages | |
function wpb_list_child_pages() { | |
global $post; | |
// does page have children? | |
$children = get_pages( array( 'child_of' => $post->ID ) ); | |
if( count( $children ) == 0 ) { | |
// not a parent page, | |
// show children page links of parent | |
$childpages = wp_list_pages( 'depth=1&sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' ); | |
} else { | |
// is a parent page | |
// show child page of this page | |
$childpages = wp_list_pages( 'depth=1&sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' ); | |
} | |
if ( $childpages ) { | |
$string = '<ul>' . $childpages . '</ul>'; | |
} | |
return $string; | |
} | |
add_shortcode('wpb_childpages', 'wpb_list_child_pages'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment