wordpress 设置wp_nav_menu的样式

gmxoilav  于 2023-06-29  发布在  WordPress
关注(0)|答案(1)|浏览(191)

我在模板中添加了三个菜单,但在显示样式时遇到问题,无法为它们指定样式。以下是三个菜单:

function register_the_menu(){
    register_nav_menus( array(
        'header_menu_fadev' => __( 'HeaderMenu', 'fadev'),
        'top_menu_fadev'  => __( 'TopMenu', 'fadev' ),
        'footer_menu_fadev'  => __( 'FooterMenu', 'fadev' ),
    ) );
}
add_action( 'after_setup_theme', 'register_the_menu');

菜单1(带下拉菜单的页眉菜单):

<nav class="header__nav">
   <ul class="align-items-center d-flex">
      <li class="nav-item dropdown mx-2">
         <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown"href="#" role="button" aria expanded="false">Home</a>
         <ul class="dropdown-menu">
            <li><a class="dropdown-item" href="#">Action</a></li>
            <li><a class="dropdown-item" href="#">Another action</a></li>
         </ul>
      </li>
      <li class="mx-2"> <a href="#">Advertise</a> </li>
   </ul>
</nav>

菜单2-3(上下菜单):

<nav class="section__left__nav">
   <ul class="align-items-center d-flex flex-wrap">
      <li class="mx-2 my-2 my-lg-0"> <a href="#" class="text-white">Home</a></li>
   </ul>
</nav>

我不能使用我定义的样式。你能告诉我如何解决这个问题吗?

if (has_nav_menu('top_menu')) {
        wp_nav_menu(
            array(
                theme_location'  => 'footer_menu',
                'menu_id'      => 'menu-1',
                'items_wrap'      => '<ul  class="align-items-center d-flex flex-wrap"><li class="mx-2 my-2 my-lg-0"><a class="text-white">%3$s</a></li></ul>',
                'fallback_cb'     => false,
                )
        );
    }
7rfyedvj

7rfyedvj1#

register_nav_menus中,您定义了如下页脚菜单:

'footer_menu_fadev'  => __( 'FooterMenu', 'fadev' ),

wp_nav_menu for theme_location中,您应该将参数更改为

theme_location'  => 'footer_menu_fadev' // not this 'footer_menu',

相关问题