sledgeweight
sledgeweight

Reputation: 8105

Different loop count conditionals within same loop in PHP?

intricate grid layout

I'm currently trying to wrap the first 2 posts in a div with the video and then output the remaining posts with a div wrapped around every 3 posts, as per image.

the line

if( $wp_query->current_post < 2 ): 

i've also tried with

if($count < 2)

heres a condensed version of what i have so far: Any suggesttions would be really appreciated.

<div class="row-fluid">
    <div class="span8">
        <video></video>
    </div>
    <?php $count = 1; ?>
    <?php if ( have_posts() ) : ?>
    <?php while ( have_posts() ) : the_post(); ?>
    <?php if( $wp_query->current_post < 2 ):?>
    <div class="span4">
                   // content
    </div>
    <?php if($count % 2 == 0) {
        echo '</div><div class="row-fluid">';
    }?>

    <?php else: ?>

    <div class="span4">
        //content
    </div>
    <?php if($count % 3 == 0) {
        echo '</div><div class="row-fluid">';
    }?>
    <?php $count++;?>
    <?php endif; ?>
    <?php endwhile; ?>
    <?php echo '</div>'; ?>
</div>
<?php else : ?>
<article>default wp stuff</article>
<?php endif; ?>

Upvotes: 0

Views: 229

Answers (1)

Anyone
Anyone

Reputation: 2835

I think it's an easier solution to just echo all your content and use css (float: left) to position the content properly.

<div style="width: 900px;">
  <div style="float: left; width: 600px; height: 400px;">
      some content
  </div>
  <?php foreach($post_list as $post_item): ?>
    <div style="float: left; width: 300px; height: 200px;">
      <?= $post->getContent(); ?> or what ever you use
    </div>
  <?php endforeach; ?>
  <br style="clear: left; display: none;" />
</div>

Note that I'm not that experienced with CSS but I hope this can point you in the right direction.

Upvotes: 1

Related Questions