How do I avoid Post 11, Post 12" from 4th page of Pagination?
- Total number of posts in my blog ( say 15 )
- Maximum number of posts, I want to show ( say $max = 10)
- Posts per page should be 3 only.
$max = 10;
$items_per_page = 3;
$paged = ( get_query_var('paged') > 0 ) ? get_query_var('paged') : 1;
$query = new WP_Query( array( 'posts_per_page' => $items_per_page , 'paged' => $paged ) );
if( $query->have_posts() ) {
while( $query->have_posts() ) {
$query->the_post();
the_title();
}
}
$total = ceil( $max / $items_per_page ); // 4
echo paginate_links( array( 'total' => $total ) );
wp_reset_postdata();
wp_reset_query();
output
Pagination
Page 1 : Post 1, Post 2, Post 3
Page 2 : Post 4, Post 5, Post 6
Page 3 : Post 7, Post 8, Post 9
Page 4 : Post 10, Post 11, Post 12 ==> should show only "Post 10"
Note
From my question, i want to show 10 posts only. paginate_links() generates 4 links.
site.com/page/1/ = shows P1, P2, P3
site.com/page/2/ = shows P4, P5, P6
site.com/page/3/ = shows P7, P8, P9
site.com/page/4/ = shows P10, P11, P12 => Here i need to avoid P11, P12