Created
October 15, 2012 19:19
-
-
Save billerickson/3894556 to your computer and use it in GitHub Desktop.
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
/** | |
* Grid Loop Query Arguments | |
* | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/a-better-and-easier-grid-loop/ | |
* | |
* @param object $query | |
* @return null | |
*/ | |
function be_grid_loop_query_args( $query ) { | |
$grid_args = be_grid_loop_pagination( $query ); | |
if( $query->is_main_query() && !is_admin() && $grid_args ) { | |
// All Grid Loops | |
$query->set( 'orderby', 'meta_value' ); | |
$query->set( 'meta_key', 'sort_plek' ); | |
$query->set( 'order', 'DESC' ); | |
// First Page | |
$page = $query->query_vars['paged']; | |
if( ! $page ) { | |
$query->set( 'posts_per_page', ( $grid_args['features_on_front'] + $grid_args['teasers_on_front'] ) ); | |
// Other Pages | |
} else { | |
$query->set( 'posts_per_page', ( $grid_args['features_inside'] + $grid_args['teasers_inside'] ) ); | |
$query->set( 'offset', ( $grid_args['features_on_front'] + $grid_args['teasers_on_front'] ) + ( $grid_args['features_inside'] + $grid_args['teasers_inside'] ) * ( $page - 2 ) ); | |
// Offset is posts on first page + posts on internal pages * ( current page - 2 ) | |
} | |
} | |
} | |
add_action( 'pre_get_posts', 'be_grid_loop_query_args' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment