Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created January 19, 2013 14:27
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 billerickson/4572940 to your computer and use it in GitHub Desktop.
Save billerickson/4572940 to your computer and use it in GitHub Desktop.
<?php
/* Template Name: Grid Archive */
/**
* Category Loop
*
*/
function be_category_loop() {
global $post, $wp_query;
$args = array(
'posts_per_page' => 20,
'post_type' => 'post',
'paged' => get_query_var( 'paged' ),
'cat' => (int) get_post_meta( $post->ID, 'query_args', true ),
);
$wp_query = new WP_Query( $args );
if( $wp_query->have_posts() ):
while( $wp_query->have_posts() ): $wp_query->the_post(); global $post;
$classes = 0 == $wp_query->current_post || 0 == $wp_query->current_post % 2 ? 'post one-half first' : 'post one-half';
echo '<div class="' . $classes . '">';
echo '<h2 class="entry-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
echo '<div class="entry-content">';
echo '<a href="'.get_permalink().'">' . get_the_post_thumbnail( null, 'grid-thumbnail' ) . '</a>';
echo '</div>';
echo '</div>';
endwhile;
genesis_posts_nav();
endif;
wp_reset_query();
}
add_action( 'genesis_loop', 'be_category_loop' );
remove_action( 'genesis_loop', 'genesis_do_loop' );
genesis();
@billerickson
Copy link
Author

Assumptions:

  • You're storing the category ID in the custom field 'query_args'
  • The post thumbnail size you want is 'grid-thumbnail'
  • You want 20 posts per page, and for this to be paginated.

Note: This really shouldn't be done through a custom page template. Use the standard category archive (template: category.php) and you won't need to do a custom query.

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