How to output different posts per page?
Question
I want to display one blog article less than on the following pages. The following code works but the the paginaton on the first page displays 1, 2, 3, 4
and on the next pages i get the correct pagination of 1, 2, 3
– What am i doing wrong?
add_action( 'pre_get_posts', 'trr_query_offset', 1 );
function trr_query_offset( &$query ) {
if ( ! ( $query->is_home() || is_main_query() ) ) {
return;
}
$offset = -1;
$ppp = get_option( 'posts_per_page' );
if ( $query->is_paged ) {
$page_offset = $offset + ( ( $query->query_vars['paged']-1 ) * $ppp );
$query->set( 'offset', $page_offset );
} else {
$query->set( 'posts_per_page', $offset + $ppp );
}
}
add_filter( 'found_posts', 'trr_adjust_offset_pagination', 1, 2 );
function trr_adjust_offset_pagination( $found_posts, $query ) {
$offset = -1;
if ( $query->is_home() && is_main_query() ) {
return $found_posts - $offset;
}
return $found_posts;
}
``
0
pagination, query, wp-query
3 years
2020-03-30T12:51:15-05:00
2020-03-30T12:51:15-05:00 0 Answers
97 views
0
Leave an answer