我正在尝试在 WordPress 中创建多个菜单。实际上菜单已创建,我为它们分配了位置并保存,但是当我调用页脚菜单并保存其仅在页眉和页脚部分中显示页脚菜单链接时出现问题,这是我的代码,请帮助我找出错误的地方,谢谢。我正在使用 WordPress 4.1
代码:Header.php
<nav class="site-nav">
<?php
$args = array(
'theme_location' => 'primary'
);
?>
<?php wp_nav_menu( 'args' );?>
</nav>
代码:页脚.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') );
确保通过“菜单”>“管理位置”再次检查,并且每个菜单上至少有一项。
我不确定这是否是解决方案。但尝试将页脚的参数重命名为 footer_args 。
看起来您的其他菜单名为
header
而不是 primary
。您可能只需要更改 Header.php
中的代码即可
$args = array(
'theme_location' => 'primary'
);
到
$args = array(
'theme_location' => 'header'
);
wp_nav_menu
功能中传递菜单名称来显示没有主题位置的菜单。对于
标题菜单,
wp_nav_menu( array('menu' => 'Header Menu' ));
对于
页脚菜单
wp_nav_menu( array('menu' => 'Footer Menu' ));
<?php wp_nav_menu( 'args' );?>
而不是变量 $args:
<?php wp_nav_menu( $args );?>