Title: odd / even
Last modified: August 20, 2016

---

# odd / even

 *  Resolved [bjihalliday](https://wordpress.org/support/users/bjihalliday/)
 * (@bjihalliday)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/odd-even/)
 * I am looking to create alternate colours for the content on my blog the <div 
   class”words”> section. Can anyone help set up an odd/even for me?
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * [http://pastebin.com/5t2dnU5F](http://pastebin.com/5t2dnU5F)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/odd-even/#post-2687727)
 * put this in your theme’s functions.php:
 *     ```
       function odd_even_class($classes) {
   
       	global $post_num;
               $class = '';
   
       	if ( ++$post_num % 2 ) {
       		$class = 'even';
       	} else {
       		$class = 'odd';
       	}
   
       	if($class != '') {
       	  $classes[] = $class;
       	}
       	return $classes;
       }
       add_filter('post_class', 'odd_even_class');
       ```
   
 * it will add the odd even classes to the post_class:
    [http://codex.wordpress.org/Function_Reference/post_class](http://codex.wordpress.org/Function_Reference/post_class)
 * Now you can style it like so:
 *     ```
       .even .words {
       // your css
       }
       .odd .words {
       // your css
       }
       ```
   
 *  Thread Starter [bjihalliday](https://wordpress.org/support/users/bjihalliday/)
 * (@bjihalliday)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/odd-even/#post-2687729)
 * Thank you very much this has been amazing simple and handy.
 * Cheers
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/odd-even/#post-2687731)
 * You’re welcome. Glad you got it resolved.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘odd / even’ is closed to new replies.

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * Last activity: [14 years, 2 months ago](https://wordpress.org/support/topic/odd-even/#post-2687731)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
