From 1dd8d336aa74187bffd76eeb081d594cd02a2c9b Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Wed, 22 Apr 2009 08:44:37 +0000 Subject: [PATCH] Add a complementary get_* function for posts_nav_link(), props filosofo, fixes #9094 git-svn-id: https://develop.svn.wordpress.org/trunk@11049 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/link-template.php | 59 +++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 8cf15bae25..2242b3b46e 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -1421,6 +1421,45 @@ function previous_posts_link( $label = '« Previous Page' ) { echo get_previous_posts_link( $label ); } +/** + * Return post pages link navigation for previous and next pages. + * + * @since 2.8 + * + * @param string|array $args Optional args. + * @return string The posts link navigation. + */ +function get_posts_nav_link( $args = array() ) { + global $wp_query; + + $return = ''; + + if ( !is_singular() ) { + $defaults = array( + 'sep' => ' — ', + 'prelabel' => __('« Previous Page'), + 'nxtlabel' => __('Next Page »'), + ); + $args = wp_parse_args( $args, $defaults ); + + $max_num_pages = $wp_query->max_num_pages; + $paged = get_query_var('paged'); + + //only have sep if there's both prev and next results + if ($paged < 2 || $paged >= $max_num_pages) { + $args['sep'] = ''; + } + + if ( $max_num_pages > 1 ) { + $return = get_previous_posts_link($args['prelabel']); + $return .= preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $args['sep']); + $return .= get_next_posts_link($args['nxtlabel']); + } + } + return $return; + +} + /** * Display post pages link navigation for previous and next pages. * @@ -1430,23 +1469,9 @@ function previous_posts_link( $label = '« Previous Page' ) { * @param string $prelabel Optional. Label for previous pages. * @param string $nxtlabel Optional Label for next pages. */ -function posts_nav_link( $sep = ' — ', $prelabel = '« Previous Page', $nxtlabel = 'Next Page »' ) { - global $wp_query; - if ( !is_singular() ) { - $max_num_pages = $wp_query->max_num_pages; - $paged = get_query_var('paged'); - - //only have sep if there's both prev and next results - if ($paged < 2 || $paged >= $max_num_pages) { - $sep = ''; - } - - if ( $max_num_pages > 1 ) { - previous_posts_link($prelabel); - echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep); - next_posts_link($nxtlabel); - } - } +function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) { + $args = array_filter( compact('sep', 'prelabel', 'nxtlabel') ); + echo get_posts_nav_link($args); } /**