我正在尝试在 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' );
这是图片:
第一个标题菜单
页脚菜单
位置
结果
我哪里错了
最佳答案
在 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/