Skip to content

Instantly share code, notes, and snippets.

@wpperform
Last active December 10, 2015 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpperform/4411009 to your computer and use it in GitHub Desktop.
Save wpperform/4411009 to your computer and use it in GitHub Desktop.
Genesis page template that adds posts in categories to a page but displays limited post data
<?php
// Template Name: Page With Posts In Categories Condensed
//
// For Genesis framework. To use:
// 1) Create a page
// 2) Set the page template in the Page Attributes panel to this template
// 3) Turn off comments and trackbacks
// 4) Set a custom field on the page of query_args_category__and equal to the numeric ID of the category
// 5) Add additional custom fields with the same name but different category ID to display multiple categories
function wpp_custom_loop() {
global $post;
// arguments, adjust as needed
$args = array(
'category__and' => get_post_meta( $post->ID, 'query_args_category__and' ),
'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
'posts_per_page' => 10
);
// Overwrite $wp_query with our new query so the pagination functions work, since they use $wp_query
global $wp_query;
$wp_query = new WP_Query( $args );
if ( have_posts() ) :
while ( have_posts() ) : the_post();
?>
<div class="post type-post hentry">
<h2 class="entry-title">
<a href="<?php echo get_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a>
</h2>
<div class="entry-content">
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
</div><!-- .post -->
<?php
endwhile;
do_action( 'genesis_after_endwhile' );
endif;
wp_reset_query();
}
add_action( 'genesis_loop', 'wpp_custom_loop' );
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment