Reply To: Need to add some custom code just before the pagination function

Home Forums Support Need to add some custom code just before the pagination function Reply To: Need to add some custom code just before the pagination function

#229956
Jean

Hey Paul based on the answer you need to do this:

– This code you place at Inside Content Container Hook (GP Hooks)

<?php global $wp_query;
if ( ! $wp_query->is_paged ) {
    $all_posts_except_fp = ( $wp_query->found_posts - 7 ); // Get us the found posts except those on first page
    $wp_query->max_num_pages = ceil( $all_posts_except_fp / 9 ) + 1; // + 1 the first page we have containing 7 posts
} ?>

– And this goes to your functions.php

add_action('pre_get_posts', 'myprefix_query_offset', 1 );
function myprefix_query_offset(&$query) {

    if ( ! $query->is_home() ) {
        return;
    }

    $fp = 7;
    $ppp = 9;

    if ( $query->is_paged ) {
        $offset = $fp + ( ($query->query_vars['paged'] - 2) * $ppp );
        $query->set('offset', $offset );
        $query->set('posts_per_page', $ppp );

    } else {
        $query->set('posts_per_page', $fp );
    }

}

add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );
function myprefix_adjust_offset_pagination($found_posts, $query) {

    $fp = 7;
    $ppp = 9;

    if ( $query->is_home() ) {
        if ( $query->is_paged ) {
            return ( $found_posts + ( $ppp - $fp ) );
        }
    }
    return $found_posts;
}

It worked for me. Hope I’ve helped.