Jump to content

Every Third Iteration of a Loop...


pealo86

Recommended Posts

This problem is a little more complex than I thought. I'm trying (in Wordpress) to output 3 <span> elements in each iteration of the loop.

 

However each <span> element needs to advance the loop to the next iteration (if that makes sense).

 

See here:

<?php $count = 0; ?>
<?php if(have_posts()) : ?>
   <?php while(have_posts()) : the_post(); ?>
      <div class="divide">
         <span>
            <a href="<?php the_permalink(); ?>">
               <span class="icon-home"><img src="<?php bloginfo('template_url'); ?>/image/icon-home-01.png" alt="Property" /></span>
               <span class="content"><?php the_title(); ?></span>
            </a>
         </span>
      </div>
      <?php $count ++; ?>
   <?php endwhile; ?>
<?php endif; ?>

 

There needs to be 3 <span> elements inside each <div class="divide" /> element.

 

One thing I did try was to include a for loop inside 'div.divide' so that it output 3 of the <span> elements. But then I realised it simply output 3 of the same elements (e.g. all of the 'the_title()' fields were the same instead of advancing onto the next post).

 

Does anyone have an idea how I can achieve it? Hopefully that makes sense, but I'm having trouble explaining it!

 

MOD EDIT:

 . . . 

tags fixed . . .

Link to comment
Share on other sites

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.