【问题标题】:WordPress Menus - Don't Show Sub-PagesWordPress 菜单 - 不显示子页面
【发布时间】:2011-10-29 15:51:09
【问题描述】:

我使用 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;?>

任何帮助将不胜感激。

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    我刚刚完成了一个网站,它要求在侧边栏中有一个主菜单和一个子菜单

    我如何完成任务是让主菜单的深度为 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; ?>
    

    我希望这至少会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-08
      • 2013-10-16
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 2019-12-01
      • 1970-01-01
      相关资源
      最近更新 更多