Support » Fixing WordPress » Highlight current category

  • amanzi


    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…

Viewing 4 replies - 1 through 4 (of 4 total)
  • amanzi


    You can see this working on my site, but I don’t have that many categories at the moment. I developed this for my next site which will rely very heavily on categories.



    Well there is a plugin, that is doing the same:

    but: my problem is: I want to see the category highlighted in the single view in single.php also.



    I guess i’ve found an easy way in order to highlight the current category also in single view. i’m using the WordPress Plugin: Highlight Current Category
    by filosofo and just put the category id together with the article id in the url bar. so the address instead of weblog/?p=3 is no for example weblog/?p=3&cat=1. you can see on my site how that it really works 😉

    I need the following: on the front page, there should be a list of categories (on a sidebar) with a “home” link above ’em which should be highlighted. On other pages, the plugins listed above should work as usual (however, the “home” link should be inactive).

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Highlight current category’ is closed to new replies.