i want to show more posts on my subpages
My code in the functions.php
function number_of_posts($query)
{
if($query->is_main_query())
{
$paged = $query->get( 'paged' );
if ( ! $paged || $paged < 2 )
{
}
else
{
$query->set('posts_per_page', 24);
}
}
return $query;
}
add_filter('pre_get_posts', 'number_of_posts');
Problem:
On the first page i get a wrong pagination. It shows a link to subpage 4 but a subpage 4 doesn’t exit.
I think i must add something like this
....
if ( ! $paged || $paged < 2 )
{
// show only 10 posts but calculate the pagination with 18 posts
}
.....
Is this possible?
Here is a modified version of a post I have done on WPSE a while ago
FROM WPSE
STEP 1
We neet to get the
posts_per_page
option set from the back end (which should be set to 10) and also set youroffset
which we are going to use. That will be14
as you will need 24 posts on page one and 24 on the rest.If you don’t want to alter the
posts_per_page
option, you can then just simply set the variable$ppg
to10
STEP 2
On page one, you’ll need to subtract the
offset
toposts_per_page
STEP 3
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 4
Lastly, you need to add your offset to
found_posts
otherwise your pagination will will not show the last pageALL TOGETHER
This is how your complete query will look like that should go into functions.php
and in the main query where you have specified all the arguments for Wp_Query . please add
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;