Show children connected to parent pages

Can someone assist with a function code that displays children on a parent page.

I have breadcrumbs for when standing on child page going back to parent but,

I need standing on parent page to display all children in UL/li list below the page title

Topic children pages Wordpress

Category Web


You Can use wp_list_pages() function.

<?php
wp_list_pages(array(
    'title_li' => NULL,
    'child_of' => 123, // ID of parent page
));
?>

Using inside page loop or page.php

<?php
while ( have_posts() ) : the_post();

wp_list_pages(array(
    'title_li' => NULL,
    'child_of' => get_the_ID(),
));

endwhile;
?>

Add this to you theme, just after the title part that displays the title.

<?php
$args   = array(
    'post_type' => 'page', // Only get pages (attachments can be listed as children)
    'posts_per_page' => -1, // List all the children
    'post_parent' => $post->ID // Get pages that are the children of the current page
);
$parent = new WP_Query($args);
if ($parent->have_posts()): // If there are any children
?>
<ul>
<?php while ($parent->have_posts()): $parent->the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php endif; wp_reset_postdata(); ?>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.