Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress Loop: how to wrap each 3 posts into a div?

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!

like image 870
lushiano Avatar asked Nov 13 '22 15:11

lushiano


1 Answers

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>
like image 150
lushiano Avatar answered Dec 25 '22 19:12

lushiano