2012-02-01 27 views
1

我今天開始使用WP,並試圖做一些自定義來適應我的需求。Wordpress中可交換的二級菜單

我選擇了兩個菜單頂部的一個主題,我們稱之爲「中」菜單。

所以,讓我們假設主(主菜單)包括: (首頁,站點,應用程序,照片,聯繫人)

然後,我想有不同的菜單功能,用於第一個 的每個選擇for Home - 沒有二級菜單 for Webs - 具有鏈接頁面(web1,web2,web3,web4 ...)的「Mid1」菜單 for Apps - 具有鏈接到頁面的「Mid2」菜單(App1,App2,App3 ,App4 ...) 用於照片 - 具有鏈接到頁面(Gallery1,Gallery2,Gallery3,Gallery4 ...)的「Mid3」菜單 用於聯繫人 - 沒有二級菜單

是否有這樣的插件可以處理這個問題,或者我應該放一些if - 然後在代碼中的某處?

Tx。

回答

0

我會使用WordPress的內置頁面水印,然後生成基於該水印的子菜單。

所以,你需要在每個子頁與它的父母,你可以做WordPress的編輯器的右側邊欄,或使用拖放插件像PageMash關聯:

  • 首頁
    • 腹板
      • 纖維網1
      • 網絡2
      • 網絡3
      • 的Web 4
    • 應用
      • 應用1
      • 應用2
      • 應用3
      • 應用4
    • 照片
      • 圖庫1
      • 圖庫2
      • 圖庫3
      • 畫廊4
    • 聯繫

然後,一些代碼添加到您的模板(可能page.php)列出當前頁面的兒童。您可能會需要調整它來獲取你想要什麼,這只是讓你開始:HTTP://codex.wordpress

<?php 
    /* List the child pages */ 
     if ($post->post_parent) { 
      $ancestors=get_post_ancestors($post->ID); 
      $root=count($ancestors)-1; 
      $parent = $ancestors[$root]; 
     } else { 
      $parent = $post->ID; 
     } 

      $parent_title = get_the_title($post->post_parent); 
      $children = wp_list_pages("title_li=&child_of=". $parent ."&echo=0"); 

      if ($children) { ?> 

       <ul> 
       <?php echo $children; ?> 
       </ul> 
      <?php } 
       /* If there are no children, do something else, or nothing */ 
       else { } ?> 
+0

請參閱您的子菜單的更多幫助/定製wp_list_pages文檔。org/Function_Reference/wp_list_pages – 2012-02-01 15:21:56

+0

我發現了一種調用精確菜單的方法,用於放置在頁面數組中的確切頁面。它不會自動工作,所以當我添加新頁面時,我必須手動將它的ID放在數組中,但它解決了我的問題:) – Balkyto 2012-03-10 17:03:46