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

当有多个菜单时,在菜单上丢失页面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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dqb78642 2018-09-13 17:54

    Add for all the instance you have add 'menu'=>'name', Hope it helps

    评论
    解决 无用
    打赏 举报
  • dongtuwu8548 2018-09-17 10:00

    please add the Parameters menu, menu_class, menu_id.

    and use this link for the further https://developer.wordpress.org/reference/functions/wp_nav_menu/

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题