signyourbikeout
Member
Posted 1 year ago #
Hello,
I've used plugins and some php to add the current-menu-item class to the wordpress menu on single pages before, but it seems that with the update to WordPress 3.0 and the new menu system, the plugins and hacks I was using no longer work.
Does anyone have a way to add a class to the menu during single.php views for the new menu?
Thanks,
Paul
signyourbikeout
Member
Posted 1 year ago #
What I was needing was a way to highlight the page in the nav that was pulling specific categories. So my request wasn't really clear. The best way to accomplish what I was looking for is to add a class to the body tag that names the category. Then you can use css to highlight the specific nav item.
<?php $class='';
if(is_single()) {
$category = get_the_category();
$class .= $category[0]->slug;
}?>
<body <?php if (function_exists('body_class')) body_class($class ); ?>>
Then for instance with CSS,
.articles #menu-item-10 {
background-color:#000;
}
Hope that helps someone else
Try specifying CSS for the following classes: .current-menu-item and current-post-parent.
object81
Member
Posted 1 year ago #
Thanks guys! You got me on the right track after hours of searching. I wanted to mark a specific top menu item as active when a single post is viewed. Namely the "Archive" item. All I needed was this little CSS snippet (I use a Child Theme of TwentyTen):
.single-post #menu-item-2299 a {
color:#fff;
}