Jump to content

While loop, do something after every 2 loops


Mundo

Recommended Posts

This is for display purposes...

 

Is there any way i can make my while loop do the following:

 

<div class="1">$item1</div>
<div class="2">$item2</div>
<div class="break"></div>
<div class="1">$item3</div>
<div class="2">$item4</div>
<div class="break"></div>
<div class="1">$item5</div>
<div class="2">$item6</div>
<div class="break"></div>

 

Really can't think of a nice, simple, elegant solution for this...

 

The problem there is im using Wordpress...

 

So my code is:

 

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

// first iterations:

<div class="1">

	<h3><?=the_title()?></h3>

	<?=get('custompost_image')?>

	<?=get('custompost_blurb')?>

</div>

// second iterations

<div class="2">

	<h3><?=the_title()?></h3>

	<?=get('custompost_image')?>

	<?=get('custompost_blurb')?>

</div>

// third iterations

<div class="break"></div>

//reset back to 0...

<?php endwhile; ?>

 

If you get me?

There's nothing special about this wordpress code aside from the fact that it uses the colon syntax rather than the curly brace syntax.  It only APPEARS to be custom wordpress code, when in reality it's just regular old PHP.

 

Simply stick the relevant IF statements inside your loop here.

 

-Dan

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.