Pagination: posts limited only on first page
-
Hello,
According to https://www.ads-software.com/support/topic/front-page-query_posts-limit-posts-only-on-first-page-1
I found that 5 posts from offset are not displayed on last page – they needs next page.I have 408 published posts.
So$wp_query->max_num_pages = 41
.But index.php is:
global $query_string; $front_limit = 5; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $offset = ( is_paged() ? ( ($paged - 2) * $posts_per_page + $front_limit ) : 0 ); $posts_per_page = get_option('posts_per_page'); $my_query = '&ignore_sticky_posts=1'; $my_query .= '&offset='.$offset; $my_query .= '&paged='.$paged; if ( !is_paged() ) : $my_query .= '&posts_per_page='.$front_limit; else : $my_query .= '&posts_per_page='.$posts_per_page; endif; query_posts( $query_string . $my_query );
So on 41 pages I have 405 posts (41 pages limited to 410 posts, but front page takes only 5 posts and following pages have offset by those 5 taken from front page).
And 3 last posts are missing.Correctly number of pages should be:
$front_limit = 5; $total_posts = $wp_query->found_posts; $posts_per_page = get_option('posts_per_page'); $total_pages = ceil( ( $total_posts - $front_limit ) / $posts_per_page ) + 1;
I have no problem to modify navigation to set max number of pages 42, but page 42 just no exists.
Temporarily I just used trick for last page (41):
if ( !is_paged() ) : $my_query .= '&posts_per_page='.$front_limit; else : if ( $paged == $wp_query->max_num_pages ) $posts_per_page += $front_limit; $my_query .= '&posts_per_page='.$posts_per_page; endif;
So page 41 displays up to 15 posts (in my case 13).
But this is not satisfactory result. If someone have an idea, please let me know.
Note: fix for first page posts navigation is
$args = array_merge( $wp_query->query_vars, array( 'showposts' => get_option('posts_per_page')) ); query_posts( $args );
before call of
"paginate_links"
Thanks in advance!
Greetings
- The topic ‘Pagination: posts limited only on first page’ is closed to new replies.