Help with a custom page template – listing contents of childpages?

hey guys,
I have no idea how to solve the following problem.
I’d love to have a page-template that lists all it’s child-pages but with the content.

e.g. Imagine I have a page called “WORK. And “Work” has childpages like “Work 01”, “Work 02”, “Work 03”, etc.

I don’t just want “WORK” to list the names of the childpages as a navigation, but rather just show all the pages under each other!

Any idea how to solve that? Thank you.

1 Answer
1

You would need to create a page template and query those pages directly.

                    $args = array(
                    'post_type' => 'page',
                    'post__in' => array(430,436,433), //The Page IDs you want to query
                     'order'    => 'ASC'
                        );

                $page_query = new WP_Query($args);

If you wanted to do this automatically and get the child pages of the current page you could use something like this:

<?php
// Set up the arguments for retrieving the pages
$args = array(
    'post_type' => 'page',
    'numberposts' => -1,

// $post->ID gets the ID of the current page
'post_parent' => $post->ID,
    'order' => ASC,
    'orderby' => title
    );
 $subpages = get_posts($args);
 // Just another WordPress Loop
 foreach($subpages as $post) :
    setup_postdata($post);
 ?>
<h4><?php the_title(); ?></h4>

 <?php the_content(); ?>

 <?php endforeach; ?>

Leave a Comment