0

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

2 Answers 2

0

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(); ?>
0

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;
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.