How to Add Odd/Even Class to Posts Listing or Comments

Your design may include different styling for odd/even comments or post lists while implementing a WordPress Theme. If a large number of comments on a post with excerpt are being shown on a blog detail page, this means styling is required here.

To accomplish this, you need to add an odd/even class to posts or comments rows. post_class and comment_class are the filters that need to be added so that these classes can be modified, respectively.

Add the following code in your Theme’s functions.php file. This will change the class for comment. The rest have to be done using CSS as there is a need to define black and grey classes here that follows the hierarchy of HTML template of comments.

User Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

    Get in Touch