Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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;}
share|improve this answer
    
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 Sep 3 '10 at 9:18

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.

share|improve this answer

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!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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