admin管理员组

文章数量:1384207

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

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

Share Improve this question asked May 1, 2020 at 23:43 iadzemoviciadzemovic 11 bronze badge
Add a comment  | 

2 Answers 2

Reset to default 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(); ?>

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

本文标签: Show children connected to parent pages