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.

I would like to change the appearance of the categories and archives widgets in the sidebar such that each category/month alternates the row color. The only way I know how to accomplish this requires modifying the PHP code in the core that generates the category and archives widgets (outputting alternating css styles depending on odd/even rows). I want to avoid modifying core files and instead do everything in the theme. Is there a way to accomplish this even/odd row styling for these widgets from within the theme or via CSS only?

share|improve this question

2 Answers 2

Use the :nth-child() pseudo-class:

li:nth-child(odd){ 
  background-color: white;
}

li:nth-child(even){
  background-color: green;
}
share|improve this answer

The only way I know how to accomplish this requires modifying the PHP code in the core that generates the category and archives widgets (outputting alternating css styles depending on odd/even rows).

If you can't do it in CSS, don't edit the core. Copy the core widget's code and create your own widget.

By the way, I really like One Trick Pony's solution (+1) but it is a CSS3 solution which I still do not trust. ( A quick look around suggests that IE8 does not support nth-child ) We are getting close to acceptable support though. I am waiting for the day...

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.