Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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>";
share|improve this question
    
Hey @Scott B: I see you'd only accepted 1 of 4 answers. Just a tip, if you find someone's answer to your question is good please do mark it as the best answer and give a vote up to anyone else who provides good input. That'll bump up their reputation and given them some recognition for their efforts. –  MikeSchinkel Aug 25 '10 at 22:39
    
Thanks, I just started posting questions a few days ago. I'm evaluating the answers. It does not mean an answer won't be selected once I have more time to review them. –  Scott B Aug 26 '10 at 11:41

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
Thanks Chris, I overlooked that. Do you know how to enable current-cat-parent? If such exists. –  Scott B Aug 26 '10 at 11:42
    
Scott, the Codex implies that the current-cat-parent class should be applied automatically to the category listing, which would mean you could select it in css with li.current-cat-parent { ... } However, I don't have a place immediately at hand to test that out. –  Chris Hubbs Aug 26 '10 at 17:17

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.