Wordpress显示当前页面和父/子

时间:2016-04-27 14:10:35

标签: php wordpress nav

我正在尝试创建一个侧边栏导航,其中包含当前页面并显示其子项(或者如果它是子页面,则是兄弟姐妹和父页面)

我只能让孩子或孩子在孩子身上展示。

我怎样才能获得

要在父页面还是子页面上显示?我不希望显示父页面的兄弟姐妹,我尝试的任何东西似乎都不起作用!

由于

            <?php
                        //GET CHILD PAGES IF THERE ARE ANY
                        $children = get_pages('child_of='.$post->ID);

                        //GET PARENT PAGE IF THERE IS ONE
                        $parent = $post->post_parent;

                        //DO WE HAVE SIBLINGS?
                        $siblings =  get_pages('child_of='.$parent);

                        if( count($children) != 0) {
                           $args = array(
                             'depth' => 1,
                             'title_li' => '',
                             'child_of' => $post->ID
                           );

                        } elseif($parent != 0) {
                            $args = array(
                                 'depth' => 1,
                                 'title_li' => '',
                                 'child_of' => $parent
                               );
                        }
                        //Show pages if this page has more than one sibling 
                        // and if it has children 
                        if(count($siblings) > 1 && !is_null($args))   
                        {?>


                             <ul class="pages-list">
                             <?php wp_list_pages($args);  ?>
                             </ul>

    <?php } ?>

0 个答案:

没有答案