2012-02-01 59 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