I am trying to list pages for a specific ID but want to include the parent page in the list

    $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.


You 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.

$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

  • Unfortunately this isn't working. I think there is firstly a syntax error. The links are meant to show in a footer on any page I am on so, the parent is going to be hardcoded, not dynamic. May 15 '20 at 9:12
  • What about this? <?php the_permalink(101); ?>"><?php echo get_the_title(101); ?> May 15 '20 at 9:18
  • So you are going to display this only on a specific page or on all pages ?
    – AcidBurn
    May 15 '20 at 13:50
  • In the footer, so on all pages May 16 '20 at 11:43
  • But you still want to keep it just for that specific ID and not to be dynamic? If that's the case, perhaps you can hardcode it. Pull the children with the PHP function and hardcode the Parent name.
    – AcidBurn
    May 16 '20 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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