Lego2012
12/13/2016 - 3:44 PM

Custom Pagination

Custom Pagination

<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.

<!-- functions.php: -->

function ppp_and_offset_posts_page( $query ) {
  if ( $query->is_home() && $query->is_main_query() && !is_admin() ) {
    $ppp = get_option( 'posts_per_page' );
    $offset = 1;
    if ( !$query->is_paged() ) {
      $query->set( 'posts_per_page',$offset + $ppp );
    } else {
      $offset = $offset + ( ( $query->query_vars['paged']-1 ) * $ppp );
      $query->set( 'posts_per_page', $ppp );
      $query->set( 'offset', $offset );
    }
  }
}
add_action( 'pre_get_posts','ppp_and_offset_posts_page' );

function posts_offset_pagination( $found_posts, $query ) {
    $offset = 1;

    if( !is_admin() && $query->is_home() && $query->is_main_query() ) {
        $found_posts = $found_posts - $offset;
    }
    return $found_posts;
}
add_filter( 'found_posts', 'posts_offset_pagination', 10, 2 );