wordpress page navigation numeric pagination showing same posts on each navigation

Hi I have a similar issue with page nav, we are showing listing and due to the amount want to page them, We have got most of the code sorted but seems to just duplicate the page and not sure the reason why. This is the code:

endwhile;
echo ‘<hr>’;
$GLOBALS[‘wp_query’]->max_num_pages = $wp_query->max_num_pages;
ct_numeric_pagination_local();

endif;
wp_reset_postdata();

echo ‘</ul>’;

echo ‘<div class=”clear”></div>’;

}
}

function ct_numeric_pagination_local() {

global $wp_query;

/** Stop execution if there’s only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;

$paged = get_query_var( ‘paged’ ) ? absint( get_query_var( ‘paged’ ) ) : 1;
$max = intval( $wp_query->max_num_pages );

/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;

/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged – 1;
$links[] = $paged – 2;
}

if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}

echo ‘<div class=”pagination”><ul>’ . “n”;

/** Previous Post Link */
if ( get_previous_posts_link() )
printf( ‘<li>%s</li>’ . “n”, get_previous_posts_link() );

/** Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ‘ class=”current”‘ : ”;

printf( ‘<li%s><a href=”%s”>%s</a></li>’ . “n”, $class, esc_url( get_pagenum_link( 1 ) ), ‘1’ );

if ( ! in_array( 2, $links ) )
echo ‘<li>…</li>’;
}

/** Link to current page, plus 2 pages in either direction if necessary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ‘ class=”current”‘ : ”;
printf( ‘<li%s><a href=”%s”>%s</a></li>’ . “n”, $class, esc_url( get_pagenum_link( $link ) ), $link );
}

/** Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max – 1, $links ) )
echo ‘<li>…</li>’ . “n”;

$class = $paged == $max ? ‘ class=”current”‘ : ”;
printf( ‘<li%s><a href=”%s”>%s</a></li>’ . “n”, $class, esc_url( get_pagenum_link( $max ) ), $max );
}

/** Next Post Link */
if ( get_next_posts_link() )
printf( ‘<li id=”next-page-link”>%s</li>’ . “n”, get_next_posts_link() );
echo ‘<div class=”clear”></div>’;
echo ‘</ul></div>’ . “n”;

}

Read more here:: wordpress page navigation numeric pagination showing same posts on each navigation

Leave a Reply

Your email address will not be published. Required fields are marked *