WordPress.org

Ready to get started?Download WordPress

Forums

Highlighting Child Pages (4 posts)

  1. theclimbingdrums
    Member
    Posted 2 years ago #

    Ok, so I'm sure that this is a relatively simple problem with an equally simple solution, but I'm stuck. I'm building a site that has a static home page with the blog page as a menu item. Pretty straight forward.

    The problem is that the blog page menu item is only assigned the class "current-menu-item" when currently clicked on it and WordPress is using the "index.php" file. Once a post is clicked and WordPress begins using the "single.php" file, that class no longer is assigned to the menu item, thereby not allowing it to be highlighted as the active menu item.

    I've read plenty of solutions that use conditional statements to determine if a page is a child page or not, but the problem I'm facing is that I'm using the WordPress 3.0 menu option in the GUI, which means that my navigation is being dynamically created.

    My question is this: How can I get the "blog" link to be the .current-menu-item when WordPress is using single.php, category.php, tag.php, etc. while still using the GUI menu system and not hardcoding in my navigation?

    Any help would be greatly appreciated!

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    I encountered this the other day and worked around it by adding a custom class to body_class() in header.php based in is_single() etc. Then I added CSS to replicate the current-menu-item highlighting via .body.single.custom-class

  3. theclimbingdrums
    Member
    Posted 2 years ago #

    Thanks for the quick response!

    I'm not sure I'm exactly following though. Do you think you could possibly post the code?

    Thanks!

  4. theclimbingdrums
    Member
    Posted 2 years ago #

    Ok, for anyone who comes across this I've figured it out (and feel quite sheepish, to be honest).

    It's as simple as using .current_page_parent for regular pages that have parentage and .current_page_ancestor for blog pages. I had read this elsewhere and must not have understood that these classes are dynamically generated by WordPress, so there you go.

Topic Closed

This topic has been closed to new replies.

About this Topic