最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Include parent page in list of child pages

programmeradmin2浏览0评论

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.

Share Improve this question asked May 14, 2020 at 11:29 user10980228user10980228 1691 silver badge14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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.

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

发布评论

评论列表(0)

  1. 暂无评论