Alternating post styles
-
So, I’ve been trying to set up some alternating post styles on this blog design I’m working on. I’ve currently managed to set up two different post classes (odd and even) and used css to change look of these classes. But I’m wondering if I can do it a better way…
What I want is to have .even posts where the featured image is full width, but cropped in height (3:2 ratio). The odd posts I want to have a much smaller image (about 50% of the width of the post) and be 1:1 ratio with the title, info and excerpt to the right of it. I have the look I want, except for the image ratios, though I feel like the code isn’t perfect…
I’m trying to learn, so is there a better way to do this?
//* Add even/odd post class for Posts in Posts page, Archives and Search results add_filter( 'post_class', 'sk_even_odd_post_class' ); function sk_even_odd_post_class( $classes ) { global $wp_query; if ( is_home() || is_archive() || is_search() ) { $classes[] = ($wp_query->current_post % 3 == 0) ? 'odd' : 'even'; } return $classes; }
CSS
/*Styrer annenhver post*/ .odd.entry { border: 0px solid #288eb0; width:100%; } .odd.entry img{ width:100%; height:auto; /*max-height:400px;*/ overflow:hidden; } .even.entry { border: 0px solid #fff; } .even.entry img{ height:auto; width:400px; }
- The topic ‘Alternating post styles’ is closed to new replies.