Created
November 3, 2011 09:01
-
-
Save worldeggplant/1336088 to your computer and use it in GitHub Desktop.
Different post count on each additional page (i.e. 9 posts on page 1, 6 on each additional page). Does some recalculations WP needs in order to get the page count right.
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 | |
$tbs_per_additional_page = 6; | |
function tbs_paged($query) { | |
global $tbs_per_additional_page; | |
if ( $query->get('post_type') == 'post_editorial' || $query->get('section') != '' ) | |
{ | |
if ( intval($query->get('paged')) > 1 ) | |
{ | |
$offset = intval(get_option('posts_per_page',9)) + ($tbs_per_additional_page*(intval($query->query['paged'])-2)); | |
$query->set( 'posts_per_page', $tbs_per_additional_page ); | |
$query->set( 'offset', $offset ); | |
$query->set( 'showposts', $tbs_per_additional_page ); | |
} | |
} | |
return $query; // Return our modified query variables | |
} | |
add_filter('pre_get_posts', 'tbs_paged'); | |
function tbs_posts($posts) | |
{ | |
global $wp_query, $tbs_per_additional_page; | |
if ( $wp_query->get('post_type') == 'post_editorial' || $wp_query->get('section') != '' ) | |
{ | |
if ( $wp_query->max_num_pages > 1 ) | |
{ | |
$wp_query->max_num_pages = intval(ceil((intval($wp_query->found_posts)-intval(get_option('posts_per_page',9)))/$tbs_per_additional_page)+1); | |
} | |
} | |
return $posts; | |
} | |
add_filter ('the_posts', 'tbs_posts'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment