

再次折腾,wordpress导航继续研究
source link: https://yjyj.net/learn/wordpress-learn/4447.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

再次折腾,wordpress导航继续研究
上一次稍微整理了点wordpress导航的相关资料http://yjyj.net/learn/wordpress-learn/3774.html
趁着这次请假回山东空闲不少,赶紧的继续折腾起.
既然资料齐备,剩下的就是动手开工了.
为了显示哥的决心,当然是要拿哥心爱的囧客圈(http://jokeoo.com)开刀.
为了让无意中来到这里的小伙伴也能尽快熟悉上手,哥就不拽那些装逼的了.
直接上脑残小白无脑版:
0.先给你的主题注册一个导航:
拿囧客圈做例子,代码伺候:
//添加导航 register_nav_menus(array( 'top-menu' => '顶部菜单', ));
1.接着再主题内原导航菜单的位置用这个替换:
<?php wp_nav_menu( array( 'container'=>'false', 'items_wrap' => '<ul class="jokeoo-menu">%3$s</ul>', 'theme_location' => 'top-menu' ) ); ?>
当然,某些情况下,会发现哎呦卧槽怎么调用不出内容,那是因为还没在后台建立相应的导航菜单啊亲!
2.最简单的一部到了,上传好刚修改的两枚页面,接着伸出左手中指,心中挚诚的默念:"money money go my home"999999次.按下键盘上的"F5".哒铛~! 导航出现了!
当然,又有某些情况下,导航没有高亮显示,到这里,恭喜你! 你的脑残指数跟哥的淫荡指数差不远了!
没有写高亮的css,导航当然不会高亮!
于是接下来我们分析一下生成的导航代码:
你会找到这些css选择器里面的某一个:
current-post-ancestor
current-menu-ancestor
current-menu-item
current-menu-parent
怎么样,只看字面意思也能够知道该怎么做了吧?没错,就是给他们写好想要的高亮样式,比如:"color:#fff;background:#000;"之类的.
再进阶一点,刚刚检查代码的时候,会发现class真是他喵的好大一串,太烦人了.
例如:
<li id="menu-item-6" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-6"><a href="http://www.jokeoo.com/">首页</a></li> <li id="menu-item-13" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-13"><a href="http://jokeoo.com/category/funnygif">囧来囧去</a></li> <li id="menu-item-8" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-8"><a href="http://jokeoo.com/category/mm">福利社</a></li>
如果你像哥一样热爱生活,当然会想要不相干的class消失掉.那么可以这么做:
过滤一下常用的当前导航高亮选择器:
current-post-ancestor
current-menu-ancestor
current-menu-item
current-menu-parent
代码如下:
/** * 移除菜单的多余CSS选择器 */ add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1); add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1); add_filter('page_css_class', 'my_css_attributes_filter', 100, 1); function my_css_attributes_filter($var) { return is_array($var) ? array_intersect($var, array('current-menu-item','current-post-ancestor','current-menu-ancestor','current-menu-parent')) : ''; } //修改上面这行可以添加更多想要保留的项目
修改之后 就会变成:
<li class="current-menu-item"><a href="http://www.jokeoo.com/">首页</a></li> <li><a href="http://jokeoo.com/category/funnygif">囧来囧去</a></li> <li><a href="http://jokeoo.com/category/mm">福利社</a></li>
哎呦,这样就成功了!
给你的class写上中意的样式吧!
哥的囧客圈小宝贝儿已经改好了,一个字:真他喵的帅毙了!
Recommend
-
181
404 此处为世界尽头请穿越到“界面”首页吧 可能因为: 网址有错误>请检查地址是否完整或存在多余字符 网址已失效>可能页面已删除 返回首页
-
46
Blogger - @nlzy -
-
9
WordPress菜单导航设置 最后更新 : 2019.04.10 首先要判断主题是否支持自定义菜单。启用主题后,后台 “ 外观-菜单 ” ,如果不支持自定义菜单,则会提示 “您的主题不...
-
12
V2EX › 程序员 想搭建一个简单的导航网站,用宝塔管理 wordpress,然后用个导航主题,可行吗?
-
9
从零开始折腾博客 (2):LMAP 搭建 Wordpress 博客 2017.11.04 |
-
9
从零开始折腾博客 (4):从 Wordpress 迁移到 Typecho 2017.11.04 |
-
7
从零开始折腾博客 (3):一键安装脚本 LAMP.sh 搭建 Wordpress 站点 2017.11.04 |
-
5
wordpress主题实现多个导航菜单方法教程 2021-12-2311:47:52评论996字 我们在使用wordpress建...
-
4
V2EX › 程序员 求一个横竖关联的简约导航源码,最好 WordPress 能用那种 ling516 · 7 小...
-
4
再一次开始折腾hexo了,为了省下高昂的服务器费用,为了利用上永久的虚拟主机。只不过可惜的是虚拟主机不能支持https,所以无奈使用了COS。还有一点就是用markdown写文章感觉确实不错,再加上github actio...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK