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:
parent
3321ea5ec8
commit
a4bfe6e799
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue