Jump to content

While loop, do something after every 2 loops


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.