display the children of the post using the current page as the main parent

How can I display the childpages of my subpages on the main page using the main page as my first loop? I can display the child pages by inputing the subpages one by one but that is not practically correct.

Main Page

SubPages

Child 1
Child 2
Child 3

SubPages

Child 1

SubPages

Child 1

CODE:

<?php
$args = array(
‘post_type’ => ‘page’,
‘post_status’ => ‘publish’,
‘posts_per_page’ => -1,
‘post_parent’ => $post->ID,
);
$query = new WP_Query($args);
if ( $query->have_posts()) :
while ($query->have_posts()) : $query->the_post(); ?>
<article class=”index-categories”>
<h1><?php the_title(); ?></h1>
</article>
<?php
endwhile;
endif;
wp_reset_postdata();?>

Read more here:: display the children of the post using the current page as the main parent

Leave a Reply

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