Hello,
I am using wp_list_categories to make my site navigation, both an upper bar and a lower bar with the children if they exist.
I want to highlight the current category and at first I was using the built-in class that WordPress assigns, but then I wanted to get it to work even in single (post) view, so I used this:
<?php
if (!is_page() && !is_home() && !is_single()){
$catsy = get_the_category();
$myCat = $catsy->cat_ID;
$currentcategory = '¤t_category='.$myCat;
}
elseif (is_single()){
$catsy = get_the_category();
$myCat = $catsy[0]->cat_ID;
$currentcategory = '¤t_category='.$myCat;
}
wp_list_categories('depth=1&title_li=&orderby=id&exclude=1,5,6,19,20,21,22&hide_empty=0'.$currentcategory);
?>
Which works great if the post is only categorized in one category...if you have it in several, it seems to highlight only the first alphabetical category.
How can I make this more robust?
To be more specific for my case: I am excluding certain categories (see above code) and if one of those comes before a category I am using, nothing gets the active class (because it only gives it to the first one, alphabetically).
I would be interested in highlighting all the categories the post falls into, or even just having it skip the categories I am excluding from the navigation...then at least one navbar item would get the active class for each post (for visual consistency).
Thanks!