父母的WordPress列表页面


Wordpress list pages by parents

我需要一些帮助为我的网站做导航,但我无法弄清楚如何使用Wordpress的wp_list_pages()函数来做到这一点。

作为参考,http://www.rwgroup.com/上的导航系统应该给出我的目标的确切想法。

在我尝试使用wp_list_pages('child_of='.$post->parent_post)之前,但似乎页面只显示它的直接父级,而忘记了它的祖先。我已经尝试了一段时间了,但我就是无法理解它。

任何想法都会很棒

尝试使用此代码列出当前页面及其祖先和子页面-

<?php
//if the post has a parent
if($post->post_parent){
  //collect ancestor pages
  $relations = get_post_ancestors($post->ID);
  //get child pages
  $result = $wpdb->get_results( "SELECT ID FROM wp_posts WHERE post_parent = $post->ID AND post_type='page'" );
  if ($result){
    foreach($result as $pageID){
      array_push($relations, $pageID->ID);
    }
  }
  //add current post to pages
  array_push($relations, $post->ID);
  //get comma delimited list of children and parents and self
  $relations_string = implode(",",$relations);
  //use include to list only the collected pages. 
  $sidelinks = wp_list_pages("title_li=&echo=0&include=".$relations_string);
}else{
  // display only main level and children
  $sidelinks = wp_list_pages("title_li=&echo=0&depth=1&child_of=".$post->ID);
}
if ($sidelinks) { ?>
  <h2><?php the_title(); ?></h2>
  <ul>
    <?php //links in <li> tags
    echo $sidelinks; ?>
  </ul>         
<?php } ?>