Display Child Pages of a Parent Page in WordPress

May 18, 2022

When you build a website in WordPress, pages are often arranged in a parent and child structure.

For example, you may have a main “Services” page. Under that, you create child pages like “Web Design”, “SEO”, and “Digital Marketing”. Now you want to show all these subpages automatically on the Services page.

In this article, you will learn a simple way to get all subpages of a parent page and show them in a clean list using WP_Query.

<?php
$parent_page_id = 10; // Change this to your parent page ID

$args = array(
    'post_type'      => 'page',
    'post_parent'    => $parent_page_id, // Get child pages of this parent
    'orderby'        => 'menu_order', // Order by menu order
    'order'          => 'ASC', // Display in ascending order
    'posts_per_page' => -1 // Get all child pages
);

$subpages = new WP_Query($args);

if ($subpages->have_posts()) : ?>
    <ul class="subpages-list">
        <?php while ($subpages->have_posts()) : $subpages->the_post(); ?>
            <li>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </li>
        <?php endwhile; ?>
    </ul>
<?php
    wp_reset_postdata(); // Reset query
else :
    echo '<p>No subpages found.</p>';
endif;
?>