Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created July 31, 2012 15:59
Show Gist options
  • Star 41 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save billerickson/3218052 to your computer and use it in GitHub Desktop.
Save billerickson/3218052 to your computer and use it in GitHub Desktop.
Genesis custom loop with pagination
<?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' )
);
/*
Overwrite $wp_query with our new query.
The only reason we're doing this is so the pagination functions work,
since they use $wp_query. If pagination wasn't an issue,
use: https://gist.github.com/3218106
*/
global $wp_query;
$wp_query = new WP_Query( $args );
if ( have_posts() ) :
echo '<ul>';
while ( have_posts() ) : the_post();
echo '<li>' . get_the_title() . '</li>';
endwhile;
echo '</ul>';
do_action( 'genesis_after_endwhile' );
endif;
wp_reset_query();
}
add_action( 'genesis_loop', 'be_custom_loop' );
remove_action( 'genesis_loop', 'genesis_do_loop' );
genesis();
@webmatter
Copy link

this one finally worked ... thanks!

@danbru1989
Copy link

danbru1989 commented Jan 27, 2018

Worked when I added genesis_posts_nav(); after the while statement like shown on the blog post: https://www.billerickson.net/code/pagination-in-a-custom-query/

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