Forums

[resolved] Show an 'active' class on wp_page_menu items when a single post is viewed (3 posts)

  1. eatanicecream
    Member
    Posted 2 years ago #

    Hi, I'm hoping that someone can help...this is driving me crazy!

    I've set up a blog section of a site with three tabs and used categories to place posts in one of the three tabs. The active state on my tabs looks fine when viewing a list of posts, but when I click into the posts (permalink) the active class disappears so I have nothing that I can style.

    I've tried the wp_classy_list plugin, but it doesn't help.

    The bit I'm working on is here if it helps: http://www.actsa.org/newsroom

    Many thanks

  2. SpankMarvin
    Member
    Posted 2 years ago #

    This is not precisely what you're after, but might achieve the same thing.

    By wrapping the list element inside a div, you could then add an if clause to check that it's in the category:

    if(in_category('whatever'))

    to define a special class for that div only if it's a single page in that category. Then you could style the list element only within that active div class accordingly.

  3. eatanicecream
    Member
    Posted 2 years ago #

    Thanks - worked it out in the end. Partly used your solution but also had to set up different templates for different single post categories and use the wp_list_categories instead of wp_lists_pages for the menu.

    Hours of fun :-)

Topic Closed

This topic has been closed to new replies.

About this Topic