Title: fix comment_class();
Last modified: August 20, 2016

---

# fix comment_class();

 *  [saintehlers](https://wordpress.org/support/users/saintehlers/)
 * (@saintehlers)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/fix-comment_class/)
 * Currently, comment_class() add “odd” or “even” to a comment’s class, presumably
   to enable alternating colors on a list of comments. It’s pretty fail when it 
   comes to threaded comments, though.
    - comment 1
 *  - first reply to comment 1
 *  - reply to the reply
 *  - Second reply to comment 1
 * comment 2
 * In this example, clearly you’d want comment 1 to be class=”odd” and comment 2
   to be class=”even” if you were alternating colors. No dice. comment_class is 
   no respecter of hierarchy or depth.
 * In this scenario you get:
    comment 1: class=”odd” first reply to comment 1: class
   =”even” reply to the reply : class=”odd” Second reply to comment 1: class=”even”
   comment 2: class=”odd”
 * Note that **comment 1** and **comment 2** both get the same class, and therefore
   if they’re used for styles, they’ll get the same appearance. True, they also 
   get “thread-odd” and “thread-even” (respectively) so you can style on that, but
   that doesn’t help with **first reply** and **second reply** — which both get 
   class=”even”. Only the first level in the hierarchy gets “thread-odd” and “thread-
   even” so you’ve still got two sequential comments with identical styling.
 * It would be useful if the “odd” and “even” assignments reset for each level of
   a thread. Then I could use them in conjunction with their level (which is already
   assigned by comment_class()) to get approprite styles. So we’d get this:
    - comment 1 (class=”odd thread-odd depth-1″)
 *  - first reply to comment 1 (class=”odd depth-2″)
 *  - reply to the reply (class=”odd depth-3″)
 *  - Second reply to comment 1 (class=”even depth-2″)
 * comment 2 (class=”even thread-even depth-1″)
    - first reply to comment2 (class=”odd depth-2″)
 * if a depth was an even number, it would have one pattern for odd/even. If the
   depth was an odd number, then it would have a different pattern for odd/even.
 * As it is, i’m considering a jQuery hack to make the style changes.

The topic ‘fix comment_class();’ is closed to new replies.