Add a complementary get_* function for posts_nav_link(), props filosofo, fixes #9094

git-svn-id: http://svn.automattic.com/wordpress/trunk@11049 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-04-22 08:44:37 +00:00
parent 3321ea5ec8
commit a4bfe6e799
1 changed files with 42 additions and 17 deletions

View File

@ -1421,6 +1421,45 @@ function previous_posts_link( $label = '« Previous Page' ) {
echo get_previous_posts_link( $label ); 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};)/', '&#038;$1', $args['sep']);
$return .= get_next_posts_link($args['nxtlabel']);
}
}
return $return;
}
/** /**
* Display post pages link navigation for previous and next pages. * Display post pages link navigation for previous and next pages.
* *
@ -1430,23 +1469,9 @@ function previous_posts_link( $label = '&laquo; Previous Page' ) {
* @param string $prelabel Optional. Label for previous pages. * @param string $prelabel Optional. Label for previous pages.
* @param string $nxtlabel Optional Label for next pages. * @param string $nxtlabel Optional Label for next pages.
*/ */
function posts_nav_link( $sep = ' &#8212; ', $prelabel = '&laquo; Previous Page', $nxtlabel = 'Next Page &raquo;' ) { function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) {
global $wp_query; $args = array_filter( compact('sep', 'prelabel', 'nxtlabel') );
if ( !is_singular() ) { echo get_posts_nav_link($args);
$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};)/', '&#038;$1', $sep);
next_posts_link($nxtlabel);
}
}
} }
/** /**