• 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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Can you describe, in human terms (as opposed to code terms), what you’re trying to accomplish? Because I’m not following at all what it is you’re trying to do.

    Putting 3 <span> tags inside of the Loop is easy:

    <?php if(have_posts()) : ?>
    	<?php while(have_posts()) : the_post(); ?>
    		<div class="divide">
    			<span></span>
    			<span></span>
    			<span></span>
    		</div>
    	<?php endwhile; ?>
    <?php endif; ?>

    …I’m also quite certain, however, that this isn’t really what you’re after. ??

    So, if you could describe it a bit better, we can try to help.

    Thread Starter 000000000

    (@pealo86)

    Hi Chip,
    Yes, human terms would probably be better!

    Okay, imagine the loop if div.divide wasn’t in it. So the loop would output one <span> element per iteration.

    However, I need it so that a div.divide element is wrapped around every 3 <span> elements. So the final output could look something like this:

    <div class="divide">
    	<span>Lorem ipsum dolor sit amet, consectetuer</span>
    	<span>Lorem ipsum dolor sit amet, consectetuer</span>
    	<span>Lorem ipsum dolor sit amet, consectetuer</span>
    </div>
    <div class="divide">
    	<span>Lorem ipsum dolor sit amet, consectetuer</span>
    	<span>Lorem ipsum dolor sit amet, consectetuer</span>
    	<span>Lorem ipsum dolor sit amet, consectetuer</span>
    </div>
    <div class="divide">
    	<span>Lorem ipsum dolor sit amet, consectetuer</span>
    	<span>Lorem ipsum dolor sit amet, consectetuer</span>
    	<span>Lorem ipsum dolor sit amet, consectetuer</span>
    </div>

    But I’m not sure how to incorporate it into a WordPress loop.

    Does that make more sense?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Need some kind of 'inner loop'’ is closed to new replies.