Last active
January 10, 2017 09:12
-
-
Save billerickson/2158395 to your computer and use it in GitHub Desktop.
Pagination in a custom query
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 | |
/** | |
* Template Name: Galleries | |
* | |
* @package BE_Gallery | |
* @since 1.0.0 | |
* @link https://github.com/billerickson/BE-Gallery | |
* @author Bill Erickson <[email protected]> | |
* @copyright Copyright (c) 2011, Bill Erickson | |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License | |
* | |
*/ | |
// Remove the standard pagination, so we don't get two sets | |
remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' ); | |
/** | |
* Galleries Loop | |
* Custom paginated loop | |
*/ | |
function be_galleries_loop() { | |
$args = array( | |
'posts_per_page' => 6, | |
'post_type' => 'post', | |
'paged' => get_query_var( 'paged' ), | |
); | |
global $wp_query; | |
$wp_query = new WP_Query( $args ); | |
if( $wp_query->have_posts() ): | |
while( $wp_query->have_posts() ): $wp_query->the_post(); global $post; | |
$classes = 'one-third'; | |
if( 0 == $wp_query->current_post || 0 == $wp_query->current_post % 3 ) | |
$classes .= ' first'; | |
echo '<div class="'. $classes . '"><h2><a href="' . get_permalink() . '">' . get_the_title() . '<br />' . get_the_post_thumbnail( $post->ID, 'be_archive' ) . '</a></h2></div>'; | |
endwhile; | |
genesis_posts_nav(); | |
endif; | |
wp_reset_query(); | |
} | |
add_action( 'genesis_after_entry', 'be_galleries_loop' ); | |
genesis(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment