Show the child and grandchild page content in Wordpress
-
28-06-2021 - |
Question
I have a page structure like this in Wordpress:
- Main Page
- Main page child
- Main page grandchild
- Main page grandchild
- Main page grandchild
- Main page grandchild
- Main page child
- Main page grandchild
- Main page grandchild
- Main page grandchild
- Main page grandchild
- Main page child
etc...
I just want to show the title/content for each child page/grandchild page on the main page it's self, please can anyone help?
No correct solution
OTHER TIPS
You should use wp_list_pages()
function, and specify a top ancestor and level of 2
.
<?php
$postid = get_the_ID();
$topid = get_top_ancestor($postid);
$args = array(
'depth' => 2,
'show_date' => '',
'date_format' => get_option('date_format'),
'child_of' => $topid,
'exclude' => '',
'include' => '',
'title_li' => '',
'echo' => 1,
'authors' => '',
'sort_order' => 'ASC',
'link_before' => '',
'link_after' => '',
'walker' => '',
'post_type' => 'page',
'post_status' => 'publish'
); ?>
<ul>
<?php wp_list_pages( $args ); ?>
</ul>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow