I have following format of sub-pages in WordPress:
About Us
-Services
-Products
-Surgery
I want to list all sub-pages with parent page like above but the code that I am using
from wpbeginner site is not working as my requirement. Can somebody tell me that
how to show sub-pages with parent page.
I tried following code in functions.php file:
function wpb_list_child_pages() {
global $post;
if ( is_page() && $post->post_parent ) {
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
} else {
$childpages = wp_list_pages( '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' );
And then use short code [wpb_childpages] in widget but it is showing only child page but I want child page with parent page