简体   繁体   English

如何在主菜单ul而不是div在WordPress中使用类

[英]How to use class on primary menu ul instead of div in wordpress

I used this php coding in wordpress to get primary menu. 我在wordpress中使用了此php编码来获取主菜单。

<?php

  wp_nav_menu( array(
    'menu' => 'Top menu',
    'theme_location' => 'primary',
    'depth' => 2,
    'menu_class' => 'nav navbar-nav',
  ));

?>

This is the output in preview. 这是预览中的输出。

<div class="nav navbar-nav">
  <ul>
    <li class="active"><a href="#"> NEWS  <span class="sr-only">(current)</span></a></li>
    <li><a href="#">FUNNY PICTURES</a></li>
    <li><a href="#">FUNNY VIDEOS</a></li>
    <li><a href="#">GOVERMENT JOBS</a></li>
    <li><a href="#">HEALTH</a></li>
    <li><a href="#">BEST SHOPING DEAL</a></li>
  </ul>
</div>

This should work like below, not like above. 这应该像下面那样工作,而不像上面那样。 Please explain what the change is need to made in php code. 请说明需要在php代码中进行的更改。

<div>
  <ul class="nav navbar-nav">
    <li class="active"><a href="#"> NEWS  <span class="sr-only">(current)</span></a></li>
    <li><a href="#">test</a></li>
  </ul>
</div>

Look at the wordpress documentation which states clearly all the things you need . 查看wordpress文档 ,其中清楚说明了您需要的所有内容。

<?php

$defaults = array(
    'theme_location'  => '',
    'menu'            => '',
    'container'       => 'div',
    'container_class' => '',
    'container_id'    => '',
    'menu_class'      => 'menu',
    'menu_id'         => '',
    'echo'            => true,
    'fallback_cb'     => 'wp_page_menu',
    'before'          => '',
    'after'           => '',
    'link_before'     => '',
    'link_after'      => '',
    'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    'depth'           => 0,
    'walker'          => ''
);

wp_nav_menu( $defaults );

?>

i didn't clearly understand your question but from what i have understood you may use container class to add class to the div folder and menu_class add class name to ul element . 我不清楚您的问题,但据我了解,您可能会使用容器类将类添加到div文件夹中,而menu_class将类名称添加到ul元素中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM