如何自定义wp_nav_menu [英] How To Customise wp_nav_menu

查看:75
本文介绍了如何自定义wp_nav_menu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个wordpress主题,并且试图在标题下方添加一个顶部菜单.

I am developing a wordpress theme and I am trying to add a top menu below the title.

我正在使用wp_nav_menu来正确显示页面,但我不知道该如何设置样式.

I am using the wp_nav_menu which displays the pages properly but I do not know how to style it.

推荐答案

法典中描述了选项.您可以简单地复制/粘贴示例代码,然后添加自己的类和ID,就像我在下面所做的那样:

The options are described in the codex. You could simply copy/paste the example code and add your own classes and IDs, like I do below:

<?php $defaults = array( 
 'container_class' => 'my-container-class', 
 'container_id'    => 'my-container-id',
 'menu_class'      => 'my-menu', 
 'menu_id'         => 'my-menu-id',
 'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
); ?>

<?php wp_nav_menu( $defaults ); ?>

%items_wrap部分中说明了%1 $ s和类似内容.本质上,它们是用于选择代码中这些自定义类和ID的位置.设置完成后,打开您的style.css文件并开始乐趣.

The %1$s and similar are explained in the $items_wrap section. Essentially they are for choosing where you want these custom classes and IDs in the code. Once it's all set, open your style.css file and start the fun.

.my-container-class {
 /* set your rules here */
}

#my-container-id {
 /* and so on... */
}

另一个更简单的选项,只需要任何代码检查器和一些CSS的基本知识.由Wordpress生成的ID和类足以解决问题.

The other, simpler option, only requires any code inspector and some basic knowledge of css. The IDs and classes generated by Wordpress would be enough to do the trick.

这篇关于如何自定义wp_nav_menu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆