Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created March 20, 2012 20:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save billerickson/2140818 to your computer and use it in GitHub Desktop.
Save billerickson/2140818 to your computer and use it in GitHub Desktop.
Better grid loop for secondary query
<?php
/** Template Name: Books **/
add_action( 'genesis_after_post_content', 'be_list_posts' );
/**
* List Posts
*
*/
function be_list_posts() {
$args = array(
'post_type' => 'books',
'posts_per_page' => -1
);
$loop = new WP_Query( $args );
if( $loop->have_posts() ):
echo '<div class="book-listing">';
while( $loop->have_posts() ): $loop->the_post();
$classes = 'book one-third';
if( 0 == $loop->current_post || 0 == $loop->current_post % 3 )
$classes .= ' first';
echo '<div id="book-' . $loop->current_post . '" class="' . $classes . '">';
the_post_thumbnail();
the_title();
echo '</div><!-- .book -->';
endwhile;
echo '</div><!-- .book-listing -->';
endif;
wp_reset_query();
}
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment