How can I retrieve a list of a Wordpress page's sibling pages?

后端 未结 4 1877
忘了有多久
忘了有多久 2021-02-19 04:08

I am trying to create a list of sibling pages (not posts) in WordPress to populate a page\'s sidebar. The code I\'ve written successfully returns a page\'s parent\'s title.

4条回答
  •  我寻月下人不归
    2021-02-19 04:42

    $post->post_parent is giving you the parent ID, $post->ID will give you the current page ID. So, the following will list a page's siblings:

    wp_list_pages(array(
        'child_of' => $post->post_parent,
        'exclude' => $post->ID
    ))
    

提交回复
热议问题