Highlight current category
-
I’ve just figured out how to highlight the current category using the list_cats tag.
I have a lot of categories and I display them in the sidebar using the list_cats() tag. When I’m viewing a category, I want the current category to have different formatting to the rest.
Here’s how I did it…
In the wp-includes/templates-functions-category.php file, I edited the list_cats() function slightly. I found this:
$link = '<a href="'.get_category_link($category->cat_ID).'" ';
I changed it to this:
if ( $category->cat_name == single_cat_title('', FALSE)) {
$link = '<a href="'.get_category_link($category->cat_ID).'" class="current-cat" ';
} else {
$link = '<a href="'.get_category_link($category->cat_ID).'" ';
}Now you can style the current category by specifying the ‘current-cat’ class in your stylesheet.
I don’t know that much about php, but I know it works for my blog – hope it works for yours too. Let me know if this works for you or whether there’s an easier way to do it…
- The topic ‘Highlight current category’ is closed to new replies.