Forums

[resolved] Highlight Current Category Single Page With New WP3.0 wp_nav_menu (4 posts)

  1. 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

  2. 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

  3. xiana
    Member
    Posted 1 year ago #

    Try specifying CSS for the following classes: .current-menu-item and current-post-parent.

  4. 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;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic