I need to have a different amount of posts per page on the first page that on the other pages.
For example, this is what I need
- Total posts: 6
- First page: showing 3 posts
- Following page: showing 2 posts per page
Here's my code:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$fp_limit = 3; // first page limit
$limit = 2; // following page limit
$offset = 0; // default offset
if( $paged == 1 ) {
$limit = $fp_limit;
} else {
$offset = $fp_limit + ( ($paged - 2) * $limit );
}
$args = array(
'post_type' => 'my_post_type',
'post_status' => 'publish',
'offset' => $offset,
'posts_per_page' => $limit,
'caller_ get_ posts' => -1, // remove sticky post
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'my_taxo',
'field' => 'slug',
'terms' => array('slug1', 'slug2', 'slug3')
)
)
);
$my_query = null;
$my_query = new WP_Query($args);
// basic loop
if( $my_query->have_posts() ) :
while ($my_query->have_posts()) : $my_query->the_post();
...
endwhile; endif; // archive loop
if (function_exists('wp_pagenavi')){ wp_pagenavi( array( 'query' => $my_query ) ); }
wp_reset_query();
At first page in archive, this code assumes:
Well, 6 posts total and 3 posts per page. So I need 2 archive pages and the pagination I present to you is:
[1] [2]
However, any other page in archive the code assumes:
Well, 6 posts total and 2 posts per page. So I need 3 archive pages and the pagination I present to you is:
[1] [2] [3]
Need a little help to fix this.
'caller_ get_ posts'
contains spaces and is not valid. Second, it's deprecated. Useignore_sticky_posts
instead.