Reputation: 71
I'm trying this:
<?php query_posts('cat=6'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div>
<?php $counter=3; ?>
<?php the_post_thumbnail(); ?>
<?php $counter++; ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
But it's not working! :/ Thank you!
Upvotes: 5
Views: 2359
Reputation: 71
Thanks for your support guys! :) I tried both solutions but didn't work, I ended up with this and works perfectly!
<?php query_posts('cat=6'); ?>
<?php $variable=0;?>
<div>
<?php while ( have_posts() ) : the_post(); ?>
<?php if(($variable+1)<4){ ?>
<a href="<?php echo get_post_meta($post->ID, 'colaborador-link', true); ?>" target="blank">
<?php the_post_thumbnail(); ?>
</a>
<?php $variable+=1; ?>
<?php }else{ ?>
<?php $variable=1; ?>
</div>
<div>
<a href="<?php echo get_post_meta($post->ID, 'colaborador-link', true); ?>" target="blank">
<?php the_post_thumbnail(); ?>
</a>
<?php }?>
<?php endwhile; ?>
</div>
Upvotes: 1
Reputation: 2493
<?php query_posts('cat=6'); ?>
<?php if (have_posts()) : ?>
<?php $counter=0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php if($counter%3==0) : ?>
<div>
<?php $counter=3; ?>
<?php the_post_thumbnail(); ?>
<?php $counter++; ?>
</div>
<?php else:
//Some code for other posts..
endif;
?>
<?php $counter++; ?>
<?php endwhile; ?>
<?php endif; ?>
Upvotes: 0
Reputation: 1105
I haven't tested it with wordpress so i'm not 100% sure it'll work. The idea is to use the modulus operator (see an example that matches your needs here http://codepad.org/78d2aAKp)
<?php query_posts('cat=6'); ?>
<?php if (have_posts()) : ?>
<!-- Your div starts here -->
<div>
<?php
while (have_posts()) :
the_post();
$counter = 0;
if($counter%3 == 0 && $counter > 0):
?>
<!--Close and then open the div-->
</div><div>
<?php
endif;
?>
<?php the_post_thumbnail(); ?>
<?php $counter++; ?>
<?php endwhile; ?>
</div><!--/Your div ends here -->
<?php endif; ?>
Upvotes: 0