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 badge2 Answers
Reset to default 0Add 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
版权声明:本文标题:Show children connected to parent pages 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744511947a2609938.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论