Skip to content

Instantly share code, notes, and snippets.

@themeblvd
Last active August 29, 2015 14:04
Show Gist options
  • Save themeblvd/c810ac27369d8c2481df to your computer and use it in GitHub Desktop.
Save themeblvd/c810ac27369d8c2481df to your computer and use it in GitHub Desktop.
<?php
function my_post_grid() {
global $wp_query;
global $post;
// Open first row
echo '<div class="row">';
$i = 1;
while ( have_posts() ) {
the_post();
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' ); // We want the URL to the full size image
?>
<div class="col-sm-3">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2 class="entry-title"><?php the_title(); ?></h2>
<a href="<?php echo $thumb[0]; ?>" class="themeblvd-lightbox mfp-image">
<?php the_post_thumbnail('grid_3'); ?>
</a>
<?php the_content(); ?>
</div>
</div>
<?php
// Every 4th post, but not the very last post
if ( $i % 4 == 0 && $i != $wp_query->post_count ) {
// Close current row
echo '</div><!-- .row (end) -->';
// Open next row
echo '<div class="row">';
}
// Increment the counter
$i++;
}
// End final row
echo '</div><!-- .row (end) -->';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment