Categories Listing with “selected” category highlighted

Is there a way to draw the categories listing and highlight the current category being viewed?

In addition, it would be great to highlight the current category if a post or page that’s assigned to it is being viewed.

Read More

Any help much appreciated…

Here’s my current code (I’m excluding the default “uncategorized” category)…

  echo "<div class='menu top'><ul>";
    $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
    $cat_args['title_li'] = '';
    $cat_args['exclude_tree'] = 1;
    wp_list_categories(apply_filters('widget_categories_args', $cat_args));
  echo "</ul></div>";

Related posts

Leave a Reply

2 comments

  1. The WordPress Codex for the wp_list_categories tag is actually pretty helpful here – WordPress is already assigning a class to the < li > tag of the current category.

    At that point you just need to add an entry to your theme’s .css file to apply whatever highlighting you want to that class.

    For instance:

    li.current-cat { 
    background: #CCC; }
    

    Should give you a nice grey background.

  2. My first inclination is that you’d need to somehow apply a different class to the “current” category and then use CSS to highlight it. Hopefully that’s a start.