Wordpress wp_nav_menu help

2019-09-14 01:17发布

I am currently using wp_nav_menu to generate my nav menu. Although everything is working and menu highlighting is working, how do you get child pages to be highlighted as well?

For example, I have a menu item named "Page" and it has 3 child pages under that. So when I am in any of the child pages, I want the main Page to still be highlighted...how is that possible with using wp_nav_menu..?

2条回答
干净又极端
2楼-- · 2019-09-14 02:05

Wordpress will give the current page the class 'current-menu-item' so just add the css you want to that. e.g.

.current-menu-item {
background: #0077CC;
}

Edit:- You can target the child menu items with

.sub-menu .current-menu-item {
background: #0077CC;
}

Edit2:- Use this to hilight the parent menu item when on a sub page

.current-menu-parent {
background: #0077CC;
}
查看更多
我想做一个坏孩纸
3楼-- · 2019-09-14 02:07

The body_class function which WordPress has can help you out here.


http://codex.wordpress.org/Function_Reference/body_class


What you'll want is current-menu-parent which you can utilise in your CSS. Not particularly well documented as far as I can tell, but this article helps:


http://www.designisphilosophy.com/tutorials/highlight-current-page-or-category/


查看更多
登录 后发表回答