How to show all child pages of a specific wordpress page ?

Here are some other queries related to this topic …

How to show child pages of a parent page wordpress?

Show all pages of a parent page wp ?

How to display list of child pages of parent page in wordpress ?

How to get all child pages of a parent page in wordpress ?

Solution For all the above queries is ….

There are many way to show the child pages… One of them is using plugins… but i am going to do this using wp query function… I mean without plugin.

So first of all you need to login to website and go to Apearance > Theme Editor Functions.php file.

You have to add the below script to your active theme functions.php file…

get child pages of parent page wordpress through functions.php file

The wp query script below show only page title and excerpt only… you can add as per you need.

<?php
// Child pages of parent page to show in order
function parent_child_pages(){
      global $post;
	$args = array(
    'post_type'      => 'page', 
    'posts_per_page' => -1,
    'post_parent'    => '15', //place here id of your parent page	
    'order'          => 'ASC',
    'orderby'        => 'title'
 ); 
 
$childlist = new WP_Query( $args );
 
if ( $childlist->have_posts() ) : ?>

<ul class="childpages">
<?php while ( $childlist->have_posts() ) : $childlist->the_post();  ?>
<li id="child-<?php the_ID(); ?>">
  <h4><a href="<?php the_permalink();?>">
    <?php the_title();?>
    </a></h4>
  <div class="excerpt">
    <?php the_excerpt(); ?>
  </div>
  </li>
  <?php endwhile; 
	echo '</ul>';
            endif; 		 
        wp_reset_query(); 
}

//shortcode here
function parent_child_pages_shortcode($atts, $content = null) {
    ob_start();
    parent_child_pages();
	$out = ob_get_contents();
	ob_end_clean();
	return $out;
}

add_shortcode('parent_child_short','parent_child_pages_shortcode');
?>

Don’t forgot to change the ‘post_parent‘ id in your code… as defined below screenshot..

If you don’t know the how to find the ID of page then follow this tutorial ..

The above wp query is for page post type you can change that type to any custom post type to show your result.

After hit on save button..

Add the Shortcode [parent_child_short] in your page or post or wherever you want to show the result.

child pages of parent page wordpress

You can also add featured image or custom field script there to show in the result…. here is that…

For Featured image add this..

 <?php the_post_thumbnail();?>

For Custom filed value add this ..

<?php echo get_post_meta($post->ID, 'key', true); ?>

You can read more about how to get custom fields value from this topic.

If you don’t want to show or exclude some of them pages in the list then add this to query…

'post__not_in' => array( 143, 17),

You can add page ID‘s by using comma’s like below…. to exclude the pages

exclude the page

I hope this will help you.. 🙂

Feel Free to ask any query … Thanks 🙏

If this help you then.. Can you buy a Cup of Coffee for me by nst webcreation paypal--OR-- nst webcreation blog coffee cup

Published by

Narender Singh

Myself Narender Singh Thakur ( NST ) and i share my Experience/Knowledge and Tricks for folks and beginners to solve their issues while making websites through this Planet.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Click to Chat