• Hello,

    I’ve been handed a wordpress site and asked to make changes to it. One request I’ve been asked to do is to modify the main navigation bar at the top, so when a link is clicked at the top, the background image changes so you know you’re on that page. I’ve figured out how to do this by editing the style.css of my custom theme, and adding a style for “current-menu-item” (if that class is common to most themes).

    These main pages have a left navigation bar of some sub pages. The problem is, when a user clicks a sub page of one of the main pages, the top reverts to an unselected state.

    I’m hoping someone will be able to tell me places to look in my theme, or some other possibilities to extend this “current-menu-item” selection even if I click sub pages.

    Thanks,
    –Michael

Viewing 8 replies - 1 through 8 (of 8 total)
  • Link?

    If you give us a link to the site, we can take a better look at what’s going on. The name of the theme would be nice, too.

    Cheers

    PAE

    Thread Starter raterus

    (@raterus)

    My current work is unaccessible, but the publically accessible page is at Silverchair

    The theme is a custom theme that was created for us “silverchair”

    Thanks!

    OK. I can see where you’re coming from.

    Your theme doesn’t allocate the current-menu-item CSS class to any item in the main menu when you’re on the sub-pages. I think you’re going to have to find the template file that outputs the sub-pages and amend the PHP there to add the appropriate CSS class.

    Without access to the template files, I can’t really say any more than that.

    I could have missed something, of course, that someone else might pick up; but that’s what it looks like to me.

    Cheers

    PAE

    Thread Starter raterus

    (@raterus)

    Hi PAE, thanks for helping me out.

    Unfortunately my theme is not actually adding the “current-menu-item’ css class, this appears to be something in the core WordPress file (nav-menu-template.php).

    There is a function wp_nav_menu, that most pages in my theme call when they need to write out a menu. There is only one place in my theme however that writes out this main navigation bar, so I can’t think how I would modify my theme file any differently to fix this problem.

    Hope some of this makes sense, and you possibly know what I should do.

    Thanks,
    –Michael

    Is wp_nav_menu using a custom callback?

    Thread Starter raterus

    (@raterus)

    From what I see, yes. wp_nav_menu will fallback to wp_page_menu if the menu isn’t available.

    Again, this is wordpress core code, not something my template controls, so I’m not sure how relevant it is.

    Obviously I’m looking to fix my template, not wordpress!

    wp_nav_menu will fallback to wp_page_menu if the menu isn’t available.

    Then that’s not a custom callback. And wp_page_menu adds the current class automatically. So I think you may need to check again for a custom callback for wp_nav_menu.

    Thread Starter raterus

    (@raterus)

    I looked for other instances of “call_user_func”, but did not see them in wp_nav_menu, of course they could be buried in another function.

    Can you tell me what I should be looking for? Something perhaps in the theme files?

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Keep main nav "selected" when viewing sub pages.’ is closed to new replies.