[wp-hackers] WordPress 3 - Problem with menu highlighting

Chip Bennett chip at chipbennett.net
Wed Aug 10 18:40:31 UTC 2011


First things first: you asked on the wrong StackExchange site. Try this one:
http://wordpress.stackexchange.com/

<http://wordpress.stackexchange.com/>Second, you might try something like
this function, to apply single-cat highlighting:

function oenology_show_current_cat_on_single($output) {

global $post;

if( is_single() ) {

$categories = wp_get_post_categories($post->ID);

foreach( $categories as $catid ) {
$cat = get_category($catid);
// Find cat-item-ID in the string
if(preg_match('#cat-item-' . $cat->cat_ID . '#', $output)) {
$output = str_replace('cat-item-'.$cat->cat_ID, 'cat-item-'.$cat->cat_ID . '
current-cat', $output);
}
}

}
return $output;
}
// Hook current_cat function into 'wp_list_categories'
add_filter('wp_list_categories', 'oenology_show_current_cat_on_single');


Note, here it's being hooked into wp_list_categories, but you could also try
wp_list_pages, or, wp_page_menu. I'm not sure if there's a wp_nav_menu
filter? Have to check...

Hope this helps!

Chip

On Wed, Aug 10, 2011 at 11:29 AM, Dan Searle <dan at danwashere.com> wrote:

> Hi all, this is my first mail here so let me know if I'm doing anything
> wrong? I couldn't find a posting guide for this list, so I'll just go for
> it.
>
> I've already asked this on Stackoverflow but I'm getting no help there:
> http://stackoverflow.com/**questions/6855909/wordpress-3-**
> problem-with-menu-highlighting<http://stackoverflow.com/questions/6855909/wordpress-3-problem-with-menu-highlighting>
>
> I'm building a site that has a two level menu created with the admin Menu
> tool. The menu contains links to both Pages and Category lists. It doesn't
> link directly to Posts. The problem is that when you drill down into a
> Category list and click to view a single post in that Category, the menu
> highlighting gets it wrong.
>
> I've tested on a new install of WP3, set up a simple test site with a few
> pages and posts in 3 categories. All I've changed in the theme is the
> style.css to highlight the whole path.
> http://danwashere.com/wp_dev/
> Here's a direct link to view a categorised post here:
> http://danwashere.com/wp_dev/**2011/07/28/blue-rocks/<http://danwashere.com/wp_dev/2011/07/28/blue-rocks/>
>
> Everything is a page, except with the section "Advice Categories" - all
> those sub items are category lists containing categorised posts - each post
> is only categorised with a single category. The menu structure is defined
> entirely in the Menu settings.
> On that Blue Rocks page, the menu should be highlighted like this: Advice
> Categories -> Rocks, but it's highlighting the Sample Page item. And if you
> rollover the "Advice Categories" menu, you'll see that it is correctly
> highlighting the "Rocks" menu item.
>
> It seems to me that WP is applying the 'current-post-parent' class to the
> wrong top menu item, but maybe I'm missing something?
>
> Many thanks,
> Dan
>
>
> ______________________________**_________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.**com <wp-hackers at lists.automattic.com>
> http://lists.automattic.com/**mailman/listinfo/wp-hackers<http://lists.automattic.com/mailman/listinfo/wp-hackers>
>


More information about the wp-hackers mailing list