Skip to content

Instantly share code, notes, and snippets.

@nikibrown
Created July 20, 2012 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nikibrown/3152904 to your computer and use it in GitHub Desktop.
Save nikibrown/3152904 to your computer and use it in GitHub Desktop.
Add somethign before and after every group of 4 posts...
<?php $tombstones = new WP_Query('category_name=tombstones&posts_per_page=-1'); ?>
<?php $counter = 0; ?>
<?php if( $tombstones->have_posts()) : ?>
<?php while ( $tombstones->have_posts() ) : $tombstones->the_post(); ?>
<?php $counter++; ?>
<?php if ($counter % 4 == 0) echo '<div class="slide"><h1>Beginning</h1>'; ?>
<?php the_content(); ?>
<?php if ($counter % 4 == 0) echo '<h1>Ending</h1></div>'; ?>
<?php endwhile; endif;?>
<?php wp_reset_postdata(); ?>
@bgallagh3r
Copy link

Try this

<?php 
$tombstones = new WP_Query('category_name=tombstones&posts_per_page=-1');
$counter = 0;
if( $tombstones->have_posts()) :
while ( $tombstones->have_posts() ) : $tombstones->the_post();
    if ($counter % 4 == 0) echo '<div class="slide"><h1>Beginning</h1>';
    the_content();
    if ($counter % 4 == 0) echo '<h1>Ending</h1></div>';
    $counter++;                             
endwhile; endif;
wp_reset_postdata(); ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment