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 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决