php - WordPress 多菜单不工作

标签 php html css wordpress menu

我正在尝试在 WordPress 中创建多个菜单。实际上创建了菜单并为它们分配了位置并保存了但是当我调用页脚菜单并保存它时出现的问题只是在页眉和页 footer 分显示页脚菜单链接是我的代码请帮助我解决我错的地方谢谢。我正在使用 WordPress 4.1

代码:Header.php

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

代码:Footer.php

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

代码:functions.php

function register_my_menu() {
register_nav_menus( array(
    'header' => 'Header menu',
    'footer' => 'Footer menu') );
}
add_action( 'init', 'register_my_menu' );

这是图片:

第一个标题菜单 enter image description here

页脚菜单 enter image description here

位置 enter image description here

结果 enter image description here

我哪里错了

最佳答案

在 functions.php 中

// Register Navigation Menus
function register_my_menu() {
    $locations = array(
        'header' => 'Header Menu',
        'footer' => 'Footer Menu',
    );
    register_nav_menus( $locations );
}
add_action( 'init', 'register_my_menu' );

在 header.php 中

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

在 footer.php 中

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

确保通过“菜单”>“管理位置”再次检查,并且每个菜单上至少有一个元素。

关于php - WordPress 多菜单不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29614543/

相关文章:

html - 如何在 Shopify 中自定义收藏集?

javascript - 下载pdf文件时如何设置pdf文件的名称?

css - 尽管清除了 :both,但在 float 元素之后边距顶部不起作用

html - 添加空白 pre 后文本在 bootstrap 中超出 div

PHP curl 脚本未关闭连接

javascript - 如何自动生成代码并使用 Adf.ly 链接显示

php - 在真实的 Web 服务器而不是 WAMP 中放置用于连接数据库的 php 文件的位置

php - Facebook 连接和第三方 cookie?

asp.net - 如何使用 Eval 更改 TemplateField 中的颜色

jquery - 完全替换处于事件状态的图像以覆盖静态图像 Jquery Mobile