Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
List Child Pages or Subpages of a Page in the page with [gt_childpages] shortcode
<?php
function gt_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('gt_childpages', 'gt_list_child_pages');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment