Question

I'm trying to get WordPress to highlight a specific item in my menu when a post (any post) is viewed. I'm thinking that adding the post to the menu item, then suppressing display of sub-menus might help, but my 'Menus configuration' page doesn't show posts as items to add to the menu.

Does anyone know why that is, or if there's a better alternative to this method?

I'm using a copy of the default TwentyTen theme which calls wp_nav_menu in header.php.

Was it helpful?

Solution

You should be able to take the body class (single) and the nav item class (to be determined) and specify the style you'd like to show in the stylesheet. Something like this:

.single .topnav-item-29 {color: #fff; background: #333;}

OTHER TIPS

As far as i know you should just hit the button on the upper right ("options" - normally you'll find "help" there) and then add posts to it. Yea i know the UI is pretty bad at the moment. Btw: talking about v 3.0.2.

Hmm, unfortunately WordPress doesn't have Posts available by default to just drag into your editable menu. What you can do, however, is use the Links meta box and manually add the Post link. And instead of targeting a class that WordPress tacks onto menu items, that might also change and break your css in the future, you can check your screen options in the upper right of your Menus screen, and make sure you have "CSS Classes" checked in your Advanced Menu Settings.

This way, you can use your own class on that link you created and apply styles to that versus something that WordPress generates.

If you want to add a class dynamically, as in someone clicks this post link and WordPress knows that it's been clicked, and adds another class to the link, perhaps you can try a bit of JQuery - having an on Click event fire whenever that link has been clicked. Depending on how intelligent you need this link to be, you may be stepping into more advanced territory.

Hope the links help! Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top