Forked from PurpleHippoDesign/add-multiple-genesis-grid-loops
Last active
June 8, 2021 23:02
-
-
Save bhwebworks/2eb0ecd3ba7d4595f104 to your computer and use it in GitHub Desktop.
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