Created
November 20, 2013 20:07
-
-
Save brycejacobson/7570106 to your computer and use it in GitHub Desktop.
Combine next or number for WordPress wp_link_pages <!--nextpage--> function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php wp_link_pages(array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>', 'next_or_number' => 'next_and_number', 'separator' => '', 'nextpagelink' => __( '»' ), 'previouspagelink' => __( '«' ), 'pagelink' => '%')); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter wp_link_pages to do both next and number | |
*/ | |
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, $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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment