The function you’re using, wp_link_pagesCodex
, does not have the feature you’re looking for by default.
However you can easily extend it by using a callback function, registered as a filter on that functions arguments:
1 | add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add'); |
The filter will then modify the parameters that are used in that function on-the-fly and inject the missing links to the prev and next arguments which are output on the left and right side of the numbered link list (next_or_number’ => ‘number’):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | /** * Add prev and next links to a numbered page link list */ function wp_link_pages_args_prevnext_add($args) { global $page, $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'] ; return $args; } |
Usage:
1 2 3 4 5 6 7 8 9 | wp_link_pages(array( 'before' => '<p>' . __('Pages:'), 'after' => '</p>', 'next_or_number' => 'next_and_number', # activate parameter overloading 'nextpagelink' => __('Next'), 'previouspagelink' => __('Previous'), 'pagelink' => '%', 'echo' => 1 ) ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.