2011-10-29 154 views
0

我已经使用Wordpress>外观>菜单选项创建了自定义侧面菜单。这里是结构:WordPress菜单 - 不显示子页面

About Us 
Our Leadership Team 
    Name #1 
    Name #2 
    Name #3 
Our Staff and Advisory Board 
    Name #1 
    Name #2 
    Name #3 
    Name #4 

菜单显示在我想要的页面 - 但它显示完全展开。我希望它的工作方式:如果我在“关于我们” - 那么只显示顶级子选项。 (关于我们,我们的领导团队,我们的工作人员和顾问委员会)

如果我点击“我们的领导团队”,则会显示其下的三个名称。希望这是有道理的。

这是我使用的多个页面中调用这个菜单的代码:

      <?php if(is_page(array(11,354,304,302,297,232,319,317,311,309))) :?> 
           <? wp_nav_menu(array('menu' => 'main-about')); ?> 
          <?php endif;?> 

任何帮助,将不胜感激。

回答

1

我完成了一个网站,它是requred有一个主菜单和侧边栏

如何完成任务的子菜单是有主菜单,它是与深度为1(只显示父项目)。请注意,将“菜单”更改为您的菜单ID。

<?php wp_nav_menu(array('container_class' => 'menu', 'theme_location' => 'primary', 'depth' => '1', 'menu' => '3')); ?> 

然后,我所要做的就是发布子项目。我不得不动态生成菜单,而不是创建菜单。因此,不是每个子菜单都有if或switch语句,这是我使用的以下代码片段。它可以在循环之外。

注:此代码取自互联网并修改,我不知道原作者。

<?PHP 
// Get the parent's title (For display purpose) 
$str_parenttitle = get_the_title($post->post_parent); 

// This will display the child items of the parent 
// And if it's a child item, display it's siblings 
if($post->post_parent) 
    $children = wp_list_pages("title_li=&sort_column=menu_order&child_of=".$post->post_parent."&echo=0&depth=1&exclude=73"); 
else 
    $children = wp_list_pages("title_li=&sort_column=menu_order&child_of=".$post->ID."&echo=0&depth=1&exclude=73"); 
?> 

然后显示菜单

<?PHP if ($children && is_page()): ?> 
    <ul class="menu"> 
     <li <?php if (is_page() && $post->post_parent) {} else { ?>class="current_page_item"<?php } // Shows the parent item on the sub menu ?>> 
      <a href="<?php echo get_permalink($post->post_parent) ?>"><?php echo $str_parenttitle;?></a> 
     </li> 
     <?php echo $children; ?> 
    </ul> 
<?PHP endif; ?> 

我希望这至少帮助。