2

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.

3 Answers 3

3

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;}
1
  • That's a nice simple solution. It's not EXACTLY what I was after, but it's a decent workaround, so unless I get anything else, I'll mark this accepted.
    – Bobby Jack
    Commented Sep 3, 2010 at 9:18
1

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.

0

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.