Adding post_class to the loop
-
Hi,
I have a theme which displays my posts in 2 columns. I clear each left post. I currently use this wrapper around each post:
<div class="post-home<?php if( $wp_query->current_post%2 == 0 ) echo ' left'; ?>"> // post content </div>With CSS:
.post-home {width:48%; float:left; margin:0;} .post-home.left {clear:left; margin:0 4% 0 0;}But I now want to support the post_class so I can use extra Post Formats such as Aside.
That’s why I have to include the post_class to the loop (among other things ). Normally I can use something like this:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>But because I have to clear each left post I’ve build this:
<?php if( $wp_query->current_post%2 == 0 ) : ?> <article id="post-<?php the_ID(); ?>" <?php post_class('post-home left'); ?>> <?php else : ?> <article id="post-<?php the_ID(); ?>" <?php post_class('post-home'); ?>> <?php endif; ?> // post content </article>Does work fine, but I’m wondering if this can be improved/fine-tuned?
And should I use the article tag?Any thoughts?
Guido
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘Adding post_class to the loop’ is closed to new replies.