2011-12-20 65 views
0

我有一個菜單,顯示頂級頁面的第一級子頁面。我現在需要添加一個功能。現在,如果用戶導航到其中一個子頁面,我希望新頁面的子頁面也包含在菜單中。將當前頁面的孩子添加到現有菜單

For example, the menu would look like this if you were on the top level page: 
<ul> 
    <li>Item one</li> 
    <li>Item two</li> 
    <li>Item three</li> 
    <li>Item four</li> 
</ul> 
If you navigate to one of those pages, say Item two, the menu should now look like this: 
<ul> 
    <li>Item one</li> 
    <li>Item two 
    <ul> 
     <li>Child Item one</li> 
     <li>Child Item two</li> 
     <li>Child Item three</li> 
    </ul> 
    </li> 
    <li>Item three</li> 
    <li>Item four</li> 
</ul> 

And ideally, if you selected one of those child pages, say for example Child Item two: 
<ul> 
    <li>Item one</li> 
    <li>Item two 
    <ul> 
     <li>Child Item one</li> 
     <li>Child Item two 
     <ul> 
      <li>Child of Child Item two</li> 
     </ul> 
     </li> 
     <li>Child Item three</li> 
    </ul> 
    </li> 
    <li>Item three</li> 
    <li>Item four</li> 
</ul> 

堆棧溢出使我格式化我的列表作爲代碼。內置的子彈點系統不會讓我做出足夠深入的子彈點。

有誰知道如何在wordpress中做到這一點?

謝謝。

回答

0

聽起來像你問的這個(從WP documentation here拍攝):

<?php 
    $output = wp_list_pages('echo=0&depth=1&title_li=<h2>Top Level Pages </h2>'); 
    if (is_page()) { 
     $page = $post->ID; 
     if ($post->post_parent) { 
      $page = $post->post_parent; 
     } 
     $children=wp_list_pages('echo=0&child_of=' . $page . '&title_li='); 
     if ($children) { 
      $output = wp_list_pages ('echo=0&child_of=' . $page . '&title_li=<h2>Child Pages</h2>'); 
     } 
    } 
    echo $output; 
?> 
+0

不,這不符合我的要求。我已經看過那個。我希望始終顯示父級頂級頁面的第一層子級以及當前頁面的子級。 我想我真正想要的是同時感受兩組不同的頁面到we_list_pages。 – Ian 2011-12-20 03:36:34

相關問題