Last active
August 29, 2015 14:01
-
-
Save PurpleHippoDesign/78cf94e4ffef5a025708 to your computer and use it in GitHub Desktop.
Adds Multiple Genesis Grid Loops Displaying Different Categories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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