简体   繁体   English

WordPress菜单将无法正确显示

[英]Wordpress Menus won't appear correctly

I want to have a split menu with logo in the middle for my header. 我想在标题的中间有一个带有徽标的拆分菜单。 I have created two menus, using the menu tool in Wordpress, but when I choose 'Top Menu (left) to allocate this menu to the left side, the menu doesn't appear at all. 我已经使用Wordpress中的菜单工具创建了两个菜单,但是当我选择“顶部菜单(左)”将此菜单分配到左侧时,该菜单根本不会出现。 Same with the second menu and the 'Top Menu (Right)' option. 与第二个菜单和“顶部菜单(右侧)”选项相同。 They just dont show up. 他们只是不露面。 If I choose 'Primary Menu' then it does show up, but on the right hand size of the logo. 如果我选择“主菜单”,则它会显示,但是在徽标的右侧。

My header.php code is this - 我的header.php代码是这样的-

?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
    <?php lsx_head_top(); ?>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <link rel="profile" href="http://gmpg.org/xfn/11">
    <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
    <?php lsx_head_bottom(); ?>
    <?php wp_head(); ?>
    <style>
        .home-middle-block{
            border-left: 1px solid!important;
            border-right: 1px solid!important;
        } 
        .home-middle-block:before, .home-middle-block:after{
            border-bottom: 1px solid!important;
        }
    </style>
</head>

<body <?php body_class( 'lsx' ); ?>>
    <?php lsx_body_top(); ?>

    <div class="header-wrap">
        <?php //lsx_header_before(); ?>

        <header id="masthead" class="<?php lsx_header_classes(); ?>" role="banner">
            <?php lsx_header_top(); ?>

            <div class="row custom-header desktop-only">
                <div class="col-lg-5 right-menu" style="border-bottom: 1px solid;">
                    <?php //lsx_nav_menu_two(); ?>
                </div>
                <div class="col-lg-2 navbar-logo">
                    <?php lsx_nav_before(); ?>
                </div>
                <div class="col-lg-5 left-menu" style="border-bottom: 1px solid; overflow: hidden;">
                    <?php lsx_nav_menu(); ?>
                </div>
                <?php lsx_nav_after(); ?>
                <?php lsx_header_bottom(); ?>
            </div>

            <div class="row custom-header mobile-tab-only">
                <?php lsx_nav_before(); ?>
                <?php 
                if(has_nav_menu('mobile-menu')):
                    ?>
                    <nav class="primary-navbar collapse navbar-collapse">
                        <?php 
                        wp_nav_menu( array(
                            'theme_location'    => 'mobile-menu',
                            'depth'             => 3,
                            'container'         => false,
                            'menu_class'        => 'nav navbar-nav',
                            'walker'            => new LSX_Bootstrap_Navwalker(),
                        ) );
                        ?>
                    </nav>
                    <?php
                endif;
                ?>
                <?php lsx_nav_after(); ?>
                <?php lsx_header_bottom(); ?>
            </div>
        </header>

        <?php lsx_header_after(); ?>
    </div>

    <div class="wrap container" role="document" tabindex="-1">
        <div class="content role row">

Could someone please help figure out why these menus won't show up in the correct place? 有人可以帮忙弄清楚为什么这些菜单无法在正确的位置显示吗? My mobile menu won't show up on a mobile device either. 我的移动菜单也不会显示在移动设备上。

Thanks! 谢谢!

It depends on how your theme handles the menu location, you should see your template documentation or insert custom code in order to customize the theme as you want. 这取决于您的主题处理菜单位置的方式,您应该查看模板文档或插入自定义代码,以便根据需要自定义主题。

To do that add this code in 为此,请将此代码添加到

function register_my_menus() {
  register_nav_menus(
    array(
      'new-menu' => __( 'New Menu' ),
      'another-menu' => __( 'Another Menu' ),
      'an-extra-menu' => __( 'An Extra Menu' )
    )
  );
}
add_action( 'init', 'register_my_menus' );

And this code wherever you want to display your custom menu 无论您想在哪里显示自定义菜单,此代码

<?php wp_nav_menu( array( 'theme_location' => 'new-menu' ) ); ?>

If you want to know more just google it out, the source of the example code 如果您想了解更多,只需将其搜索一下,示例代码的来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM