I need some help with pagination.
The pagination should only display the current page and another numbered page, like so:
<< | 2 | …3 | >>
At the moment, it shows all page numbers:
<< | 1 | 2 | 3 | …3 | >>
Any ideas how to change this?
This is the code:
add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add');
/**
* Add prev and next links to a numbered link list
*/
function wp_link_pages_args_prevnext_add($args)
{
global $page, $pages, $numpages, $more, $pagenow;
if ( ! $args['next_or_number'] == 'next_and_number' )
return $args; # exit early
$args['next_or_number'] = 'number'; # keep numbering for the main part
if ( ! $more )
return $args; # exit early
if( $page - 1 ) # there is a previous page
$args['before'] .= _wp_link_page($page-1) . $args['link_before']
. $args['previouspagelink'] . $args['link_after']
. '</a>';
if ( $page < $numpages ) # there is a next page
$args['after'] = _wp_link_page($page+1) . $args['link_before']
. $args['nextpagelink'] . $args['link_after']
. '</a>' . $args['after'];
$args['after'] = _wp_link_page($numpages) . $args['link_before']
.'... ' . $numpages
. $args['link_after'] . '</a>'
. $args['after'];
return $args;
}