【问题标题】:I can't get both my header and footer menus to display properly in my wordpress theme我的页眉和页脚菜单无法在我的 wordpress 主题中正确显示
【发布时间】:2016-01-06 05:20:02
【问题描述】:

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

我使用页眉已经有一段时间了,但直到我尝试在页脚中添加一个菜单后,它才开始在页眉和页脚中只显示页脚菜单。我已确保 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'),
));

【问题讨论】:

  • 您没有将$args 传递给函数...

标签: php wordpress


【解决方案1】:

请改成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'));

不要忘记将菜单分配到 Options Wp --> https://codex.wordpress.org/Appearance_Menus_SubPanel

【讨论】:

  • 感谢 pio,它成功了!对不起,如果这听起来有点愚蠢,但我真的没有使用 php 的经验——如果我试图添加第三个菜单,比如在页脚中。我会添加 wp_nav_menu( array( 'theme_location' => 'footer' ) );然后添加 'footer' => __( 'Menu Footer 2' ) ?
  • 可以,但是必须添加函数 register_my_menus function() 并在footer.php中添加第三个菜单---> wp_nav_menu(array('theme_location' => 'third-footer ')); .
猜你喜欢
  • 2020-07-10
  • 1970-01-01
  • 2015-01-17
  • 1970-01-01
  • 1970-01-01
  • 2017-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多