I am trying change the number of posts that are displayed on a category pages to change on consecutive pages (page 2, 3, etc). So page one displays 7 posts, but pages 2, 3 and 4, etc of that category display only 6 posts per page (i.e. when you click 'next page' to list the older posts).
I am aware that it is relatively straightforward to change the number of posts for different categories / archive pages - but this is different, as I would like the paginated pages to have different numbers of posts.
Any ideas?
This is from an answer I recently done on WPSE. I have made some changes to suite your needs. You can go and check out that post here
STEP 1
If you have changed the main query for a custom query, change it back to the default loop
STEP 2
Use
pre_get_posts
to alter the main query to change theposts_per_page
parameter on the category pagesSTEP 3
Now, get the
posts_per_page
option set from the back end (which I assume is 6) and also set youroffset
which we are going to use. That will be1
as you will need 7 posts on page one and 6 on the restSTEP 4
On page one, you'll need to add the
offset
toposts_per_page
will add up to 7 to get your seven posts on page one.STEP 5
You must apply your
offset
to all subsequent pages, otherwise you will get a repetition of the last post of the page on the next pageSTEP 6
Lastly, you need to subtract your offset from
found_posts
otherwise your pagination on the last page will be wrong and give you a404
error as the last post will be missing due to the incorrect post countALL TOGETHER
This is how your complete query will look like that should go into functions.php