-
-
Save andyspicer/5147821 to your computer and use it in GitHub Desktop.
WP - Genesis Custom Loop
This file contains 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 | |
/** | |
* RGP-Snippet for Genesis Custom Loop | |
*/ | |
function rgp_custom_loop() { | |
global $post; | |
// arguments, adjust as needed | |
$args = array( | |
'post_type' => 'post', | |
'posts_per_page' => 1, | |
'post_status' => 'publish', | |
'paged' => get_query_var( 'paged' ) | |
); | |
// Use $loop, a custom variable we made up, so it doesn't overwrite anything | |
$loop = new WP_Query( $args ); | |
// have_posts() is a wrapper function for $wp_query->have_posts(). Since we | |
// don't want to use $wp_query, use our custom variable instead. | |
if ( $loop->have_posts() ) : | |
echo '<ul>'; | |
while ( $loop->have_posts() ) : $loop->the_post(); | |
echo '<li>' . get_the_title() . '</li>'; | |
endwhile; | |
echo '</ul>'; | |
do_action( 'genesis_after_endwhile' ); | |
endif; | |
// We only need to reset the $post variable. If we overwrote $wp_query, | |
// we'd need to use wp_reset_query() which does both. | |
wp_reset_postdata(); | |
} | |
add_action( 'genesis_loop', 'rgp_custom_loop' ); | |
remove_action( 'genesis_loop', 'genesis_do_loop' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment