Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created July 31, 2012 16:07
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save billerickson/3218106 to your computer and use it in GitHub Desktop.
Save billerickson/3218106 to your computer and use it in GitHub Desktop.
<?php
/* Template Name: Test */
/**
* Genesis custom loop
*/
function be_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', 'be_custom_loop' );
remove_action( 'genesis_loop', 'genesis_do_loop' );
genesis();
@cuxaro
Copy link

cuxaro commented Oct 1, 2018

Why make global $post? it's necessary to get pagination?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment