Skip to content

Instantly share code, notes, and snippets.

@PurpleHippoDesign
Last active August 29, 2015 14:01
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save PurpleHippoDesign/78cf94e4ffef5a025708 to your computer and use it in GitHub Desktop.
Adds Multiple Genesis Grid Loops Displaying Different Categories
<?php
//* Do NOT include the opening php tag
//* Add multiple grid loops to a page template*/
remove_action ('genesis_loop', 'genesis_do_loop'); // Remove the standard loop
add_action( 'genesis_loop', 'custom_do_grid_loop' ); // Add custom loop
function custom_do_grid_loop() {
$args = array(
'cat' => 3, // enter your category ID
'posts_per_page'=> '4', // overrides posts per page in theme settings
);
$loop = new WP_Query( $args );
if( $loop->have_posts() ):
echo '<div class="grid-loop">';
while( $loop->have_posts() ): $loop->the_post(); global $post;
$classes = 0 == $loop->current_post || 0 == $loop->current_post % 2 ? 'one-half first' : 'one-half';
echo '<div class="' . $classes . '">'; ?>
<a href="<?php the_permalink() ?>"><h3><?php the_title(); ?></h3></a>
<?php the_excerpt(); ?>
<?php echo '</div>';
endwhile;
echo '</div>';
endif;
wp_reset_query();
$args = array(
'cat' => 7, // enter your category ID
'posts_per_page'=> '2', // overrides posts per page in theme settings
);
$loop = new WP_Query( $args );
if( $loop->have_posts() ):
echo '<div class="grid-loop">';
while( $loop->have_posts() ): $loop->the_post(); global $post;
$classes = 0 == $loop->current_post || 0 == $loop->current_post % 2 ? 'one-half first' : 'one-half';
echo '<div class="' . $classes . '">'; ?>
<a href="<?php the_permalink() ?>"><h3><?php the_title(); ?></h3></a>
<?php the_excerpt(); ?>
<?php echo '</div>';
endwhile;
echo '</div>';
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment