Top

alchymyth on "Place DIV tag at the star of every specific number of posts, is it possible?"

May 12, 2010 by  

a bit expanded to close the div .pages even when an odd number of posts are in the loop:

<?php $my_query = new WP_Query('cat=2&showposts=4p&orderby=id&order=asc');
$i = 0; // initialize counter
?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php if( $i%2 == 0 ) { echo '<div class="pages">'; } ; // open div ?>
 <div>
<?php the_post_thumbnail(); ?>
<h1 class="other-item"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
</div>
<?php if( $i%2 != 0 ) { echo '</div><!-- .pages end-->'; }; //close div
$i++; //increase counter
<?php endwhile; ?>
<?php if( $i%2 != 0 ) { echo '</div><!-- .pages end-->'; }; //close div if odd number of posts in loop ?>
Share

Comments

Facebook comments:

Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!





*
Bottom