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
https://forums.phpfreaks.com/topic/250378-every-third-iteration-of-a-loop/
Share on other sites

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.