[wp-hackers] active link on menu when on a post
aesqe
aesqe at skyphe.org
Fri Jan 21 20:35:54 UTC 2011
you can filter the menu css classes. try something like this (be aware
that this function does not take custom post types or taxonomies in
account - just posts, pages and categories):
function filter_nav_menu_css_class( $classes, $item )
{
if( is_singular() )
{
global $post;
if( is_page() )
{
if( in_array($item->object_id, $post->ancestors) )
$classes[] = 'current-menu-item';
}
else // post
{
if( 'category' == $item->object )
{
$categories = get_term_children( $item->object_id, 'category');
$categories[] = $item->object_id;
if( in_category($categories, $post->ID) )
$classes[] = 'current-menu-item';
}
}
}
return $classes;
}
add_filter('nav_menu_css_class', 'filter_nav_menu_css_class', 10, 2);
On 21.1.2011 21:20, kris feathers wrote:
> Hello ya'll
> I was wondering if you could point me in the right direction. I want my
> "blog" link to stay highlighted when someone is viewing a post. The theme is
> Twenty Ten... How do I do that?
> Is there a function?
> Thank you!
> Kris
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>
More information about the wp-hackers
mailing list