2012-08-13 84 views
0

我需要一些幫助爲我的網站做導航,但我無法弄清楚如何使用Wordpress'wp_list_pages()函數來做到這一點。父母的WordPress列表頁面

作爲參考,http://www.rwgroup.com/上的導航系統應該給我準確的想法。

在我嘗試使用wp_list_pages('child_of='.$post->parent_post)之前,似乎這些頁面只顯示它是直接的父項,並且遺忘了它的祖先。我一直在嘗試一段時間,但我無法擺脫困境。

任何想法將是巨大的

+0

哦,如果它可以很容易在任何的你,該網站的深度去我想說的三到三個很淺,所以如果周圍有快速的祕籍或技巧,那將是最好的。多謝你們。 – 2012-08-13 16:06:35

+0

您不妨在WordPress Stack Exchange http://wordpress.stackexchange.com/上發佈 – dnagirl 2012-08-13 16:14:57

回答

0

試試這個代碼,列出其祖先當前頁和孩子 -

<?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 } ?> 
相關問題