dpvhv66448 2018-09-05 15:16
浏览 26
已采纳

当有多个菜单时,在菜单上丢失页面ID

I created a menu which I output on a page... each li of the menu had the page ID as an id allowing me to target specific li's.

When I added the 2nd and 3rd location for the same menu, all the id's disappeared so a lot of my styling messed up due to it no longer outputting the id's. How can I get these back when there's multiple menus?

I'm registering 3 menu locations using the following:

// Register our themes menu locations
function register_menus() {
    register_nav_menu('primary-menu', __('Primary Menu'));
    register_nav_menu('mobile', __('Mobile Menu'));
    register_nav_menu('products', __('Products Menu'));        
    register_nav_menu('footer-menu', __('Footer Menu'));
}
add_action('init', 'register_menus');

Assigning the same menu to the 3 locations:

enter image description here

Then outputting in my template with the following:

<?php if ( has_nav_menu( 'primary-menu' ) ) {
wp_nav_menu( array(
  'container'=>'div',
  'menu_class'=>'1',
  'theme_location' => 'primary-menu',
  'walker' => new CSS_Menu_Maker_Walker(),
  'items_wrap' => '<ul class="primary-menu-1">%3$s</li></ul>'
));
} ?>


<?php if ( has_nav_menu( 'mobile' ) ) {
  wp_nav_menu( array(
    'container'=>'div',
    'menu_class'=>'2',
    'theme_location' => 'mobile',
    'walker' => new CSS_Menu_Maker_Walker(),
    'items_wrap' => '<ul class="primary-menu-2">%3$s</li></ul>'
  ));
} ?>


<?php if ( has_nav_menu( 'products' ) ) {
  wp_nav_menu( array(
    'container'=>'div',
    'menu_class'=>'3',
    'theme_location' => 'products',
    'walker' => new CSS_Menu_Maker_Walker(),
    'items_wrap' => '<ul class="primary-menu-3">%3$s</li></ul>'
  ));
} ?>
  • 写回答

3条回答 默认 最新

  • douyanjing0822 2018-09-13 14:09
    关注

    Adding 'menu'=>'my-class-name', to each menu instance brings them back.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起