Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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() ); ?>

    <?php else: ?>

        <div class="entry-content-rest">
        <?php get_template_part( 'content', get_post_format() ); ?>

    <?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


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


Post2      Post3

open       Post4

Post5      Post6

Any suggestions to fix this

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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';


<?php if ( have_posts() ) : ?>

<?php while ( have_posts() ) : the_post();  ?>
        <?php /* Start the Loop */ ?>

        <div class="entry-content-<?php echo (( $wp_query->current_post == 0 ) ? 'main' : 'rest' ); if( $wp_query->current_post%2 == 1 ) echo ' left-post'; ?>">
        <?php get_template_part( 'content', get_post_format() ); ?>

<?php endwhile; ?>

additional css:

.left-post { clear: left; }
share|improve this answer
brilliant michael. it works great – Pieter Goosen May 9 '13 at 18:01
michael, how do i use your code in category.php of twenty twelve child theme. I know i need to put echo '<div>' loop without the php tags echo '</div>', but when i do it, i get the following error: Parse error: parse error, expecting ','' or ';'' in C:\Documents and Settings\Pieter\Desktop\xampplite\htdocs\wordpress\wp-content\themes\pietergoose‌​n\category.php on line 33 – Pieter Goosen May 10 '13 at 10:03
this is rather a question of when and how to switch from php tags to html tags; here is the corresponding code section: – Michael May 10 '13 at 10:10
thanks for that michael – Pieter Goosen May 10 '13 at 10:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.