I am trying to list pages for a specific ID but want to include the parent page in the list
<?php
$parent = 83;
wp_list_pages( array(
'title_li' => '',
'child_of' => $parent,
) );
?>
I tried adding 'include' => 83
but then it only listed the parent and not the children.
I am trying to list pages for a specific ID but want to include the parent page in the list
<?php
$parent = 83;
wp_list_pages( array(
'title_li' => '',
'child_of' => $parent,
) );
?>
I tried adding 'include' => 83
but then it only listed the parent and not the children.
1 Answer
Reset to default 0You can get the parent with wp_get_post_parent_id(get_the_ID()), and store it in a new variable and do the same with the children and then just showcase them in any format you want.
<?php
$theParent = wp_get_post_parent_id(get_the_ID());
if ( $theParent->ID == 83 ) { ?>
<div class="parent"><?PHP echo get_the_title($theParent); ?></div>
<ul class="children"><?PHP wp_list_pages(array(
'title_li' => '',
'child_of' => $theParent ?> </ul>
<?PHP } ?>
Hopefully, this helps