Here is my loop
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php $i = 0; while ( have_posts() ) : the_post(); ?>
<?php if ($i++ == 0) : ?>
<div class="entry-content-main">
<?php get_template_part( 'content', get_post_format() ); ?>
</div>
<?php else: ?>
<div class="entry-content-rest">
<?php get_template_part( 'content', get_post_format() ); ?>
</div>
<?php endif; ?>
<?php endwhile; ?>
and my css
.entry-content-rest {
width: 48.5%;
float: left;
border: 1px solid #ddd;
border-radius: 7px;
}
This displays my content as follow
Post1
Post2 Post3
Post4 Post5
My problem is, say post 2 is longer (have more contents) than post 3, then my columns is displayed way wacky like this
Post1
Post2 Post3
open Post4
Post5 Post6
Any suggestions to fix this
you could rewrite the full code and use the build-in loop counter
$wp_query->current_post
to fix the css classses and add a class for the first post per row to clear the float to prevent the ‘wacky sticking’;example:
additional css:
You actually don’t need to do all that work on the PHP side as CSS can handle this using nth selectors. Also, because all these children are prefixed you might as well use attribute selectors.
WORKING DEMO – JSFIDDLE
CSS
DEMO CONTENT
Using jQuery we can produce random content to check various sizes and how they affect the layout. In these cases; first item is full width, left items float left, right items float right and the next row follows the largest item. See it in action here.
HTML
JS
Colors via neilorangepeel
ok here is what I have figured out.
For displaying First post with full width and rest in two columns.
If you want to display First post with full width and rest in three columns you
can simply do this just by
The result will be