Skip to content

Instantly share code, notes, and snippets.

@sterndata
Created August 22, 2016 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sterndata/d737161f540b610a9f0e215572362fb5 to your computer and use it in GitHub Desktop.
Save sterndata/d737161f540b610a9f0e215572362fb5 to your computer and use it in GitHub Desktop.
function lcas_list_children( $atts, $content ) {
global $post;
ob_start();
$args = array(
'post_parent' => $post->ID,
'post_type' => 'page',
'orderby' => 'title',
'order' => 'ASC',
);
$myquery = new WP_Query( $args );
if ( $myquery->have_posts() ) {
while ( $myquery->have_posts() ) {
$myquery->the_post();
echo '<h2><a href="' . get_the_permalink() . '">';
the_title();
echo '</a></h2>';
the_excerpt();
}
} else {
echo 'No pages found';
}
wp_reset_query();
return '<div class="child_pages">' . ob_get_clean() . '</div>';
}
add_shortcode( 'list_child_pages', 'lcas_list_children' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment