Skip to content

Instantly share code, notes, and snippets.

@raulillana
Last active August 29, 2015 13:55
Show Gist options
  • Save raulillana/8731220 to your computer and use it in GitHub Desktop.
Save raulillana/8731220 to your computer and use it in GitHub Desktop.
WordPress query_posts with custom posts_per_page and pagination
<?php
/**
* WordPress query_posts with custom posts_per_page and pagination
*/
if( get_query_var('paged') ) $paged = get_query_var('paged');
elseif( get_query_var('page') ) $paged = get_query_var('page');
else $paged = 1;
if( !is_paged() ) $offset = '';
elseif( $paged == 2 ) $offset = '&offset=11';
else $offset = '&offset='. (11 *($paged-2)+ 11);
$posts = query_posts($query_string .'&orderby=title&order=ASC&posts_per_page=11&paged='. $paged . $offset);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment