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>";
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
asked Aug 24, 2010 at 17:20
Scott BScott B
5,69614 gold badges94 silver badges148 bronze badges
2
- 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 Commented Aug 25, 2010 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 Commented Aug 26, 2010 at 11:41
2 Answers
Reset to default 2The 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.
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.