繁体   English   中英

我的页眉和页脚菜单无法同时显示在我的wordpress主题中

[英]I can't get both my header and footer menus to display properly in my wordpress theme

我一直在尝试为我的主要超链接创建一个标题菜单,为我的社交媒体图标创建一个页脚菜单。

我已经有一个头文件了一段时间,但这只是因为我试图在页脚中添加菜单,所以它开始只在页眉和页脚中显示页脚菜单。 我已经确保所有设置在wordpress后端都是正确的,但是我仍然无法使用它。

在我的header.php中,我有:

<nav class="header-nav">
<?php $args = array('theme_location' => 'header'); ?>
<?php wp_nav_menu(); ?>
</nav>

在我的footer.php中,我有:

<nav class="footer-nav">
<?php $args = array('theme_location' => 'footer'); ?>
<?php wp_nav_menu(); ?>
</nav>

在functions.php中,我有:

register_nav_menus(array( 
'header' => __( 'Header Menu'), 
'footer' => __( 'Footer Menu'),
));

请更改为functions.php:

function register_my_menus() {
    register_nav_menus(
        array(
            'primary' => esc_html__( 'Primary Menu', 'theme_wp' ),    
            'header' => __( 'Menu Header' ),
            'footer' => __( 'Menu Footer' )
            /*'an-extra-menu' => __( 'An Extra Menu' ) */
        )
    );
}
add_action( 'init', 'register_my_menus' );

现在进入模板:

header.php文件

wp_nav_menu(array('theme_location'=>'header'));

footer.php

wp_nav_menu(array('theme_location'=>'footer'));

不要忘记进入选项Wp-> https://codex.wordpress.org/Appearance_Menus_SubPanel的分配菜单

暂无
暂无

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

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