Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    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.ww.wp.xz.cn/Function_Reference/post_class

    Now you can style it like so:

    .even .words {
    // your css
    }
    .odd .words {
    // your css
    }
    Thread Starter bjihalliday

    (@bjihalliday)

    Thank you very much this has been amazing simple and handy.

    Cheers

    Moderator keesiemeijer

    (@keesiemeijer)

    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.