简体   繁体   English

WordPress中的自定义菜单第一项活动状态

[英]Custom menu first item active state in wordpress

I would like to put the first custom menu item active, so there needs to be an "active" class. 我想将第一个自定义菜单项置于活动状态,因此需要有一个“活动”类。 How can I do that? 我怎样才能做到这一点? This is my html: 这是我的html:

<nav class="secondmenu">
    <div class="menu-captain-crew-container">
        <ul id="menu-captain-crew" class="secondnav">
         <li id="menu-item-35" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-35"><a title="Captain" href="#Captain">Captain</a></li>
         <li id="menu-item-36" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-36"><a title="Chief Stewardess" href="#chief-stewardess">Chief Stewardess</a></li>
         <li id="menu-item-37" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-37"><a title="Chief Engineer" href="#chief-engineer">Chief engineer</a></li>
         <li id="menu-item-38" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-38"><a title="Purser" href="#purser">Purser</a></li>

        </ul>
   </div>           
 </nav>

And this is the code I use to get my custom menu in my template: 这是我用来在模板中获取自定义菜单的代码:

<?php wp_nav_menu(array('menu' => 'Captain & Crew', 'menu_class' => 'secondnav')); ?>

Thanks! 谢谢!

Go to Appearance > Menus in the WordPress admin area. 转到WordPress管理区域中的外观>菜单。 Then open "Screen Options" and make sure "CSS Classes" is checked. 然后打开“屏幕选项”,并确保选中“ CSS类”。 "Screen Options" is the tab in the very top right corner of your admin screen. “屏幕选项”是管理屏幕右上角的标签。 See the screenshot below. 请参见下面的屏幕截图。

在此处输入图片说明

Then open the menu item that you wish to add the class to and type your class name in the "CSS Classes" input. 然后打开要添加类的菜单项,并在“ CSS类”输入中键入类名称。 Make sure to save your menu changes before exiting the menu screen. 退出菜单屏幕之前,请确保保存菜单更改。 See screenshot below. 请参见下面的屏幕截图。

在此处输入图片说明

This will add the class to the wrapping <li></li> of the menu item you entered the class for. 这会将类添加到您为其输入类的菜单项的包装<li></li>中。

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

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