php - Wordpress: div enclosing each group of three posts -
in wordpress, want have div wrapping around every 3 posts (because posts in grid, 3 per line, , want each line have uniform height "read more" buttons line @ bottom - http://restartcomputer.com/category/products/mac-products/). figured out (logically) how - outlined in accepted answer of question: php loop: add div around every 3 items syntax
however, i've tried , cannot code work. divs not added, @ all. here code:
if (have_posts()) : $counter = 1; ?> <div class="entries-wrapper"> <?php while (have_posts()) : the_post(); ?> //post stuff <?php if ($counter % 3 == 0) { ?> </div><div class="entries-wrapper"> <?php } $counter += 1; ?> <?php endwhile; ?> </div> //some more code <?php endif; wp_reset_query(); ?>
any idea why?
you have not entered script (line 4):
if (have_posts()) : $counter = 1; ?> <div class="entries-wrapper"> <?php while (have_posts()) : the_post(); ?> //post stuff <?php if ($counter % 3 == 0) { ?> </div><div class="entries-wrapper"> <?php } $counter += 1; ?> <?php endwhile; ?> </div> //some more code <?php endif; wp_reset_query(); ?>
i did similar in theme align posts side side:
<?php if ( have_posts() ) : ?> <?php $col = 1; ?> <?php /* start loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php if($col == 1) echo "<div class='row'>"; ?> <div class="post col<?php echo $col; ?>" id="post-<?php echo the_id(); ?>"> <?php /* include post-format-specific template content. * if want override in child theme, include file * called content-___.php (where ___ post format name) , used instead. */ get_template_part( 'content', get_post_format() ); ?> <?php (($col==1)?$col=2:$col=1); ?> </div> <?php if($col == 1) echo "</div>"; ?> <?php endwhile; ?> <?php kubrick_paging_nav(); ?> <?php else : ?>
can try moving div within while statement.