From 4bc175346f583303bfa3a8e11dab9e01e1f53461 Mon Sep 17 00:00:00 2001 From: azaozz Date: Wed, 12 Nov 2008 10:13:50 +0000 Subject: [PATCH] Fixes for previous/next page links, props Viper007Bond, fixes #8058 git-svn-id: http://svn.automattic.com/wordpress/trunk@9632 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/link-template.php | 101 ++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 30 deletions(-) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index fc86ea1ea6..17ef642a17 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -1054,38 +1054,60 @@ function get_next_posts_page_link($max_page = 0) { } /** - * Display the next posts pages link. + * Display or return the next posts pages link. * * @since 0.71 * * @param int $max_page Optional. Max pages. + * @param boolean $echo Optional. Echo or return; */ -function next_posts($max_page = 0) { - echo clean_url(get_next_posts_page_link($max_page)); +function next_posts( $max_page = 0, $echo = true ) { + $output = clean_url( get_next_posts_page_link( $max_page ) ); + + if ( $echo ) + echo $output; + else + return $output; +} + +/** + * Return the next posts pages link. + * + * @since 2.7.0 + * + * @param string $label Content for link text. + * @param int $max_page Optional. Max pages. + * @return string|null + */ +function get_next_posts_link( $label = 'Next Page »', $max_page = 0 ) { + global $paged, $wp_query; + + if ( !$max_page ) { + $max_page = $wp_query->max_num_pages; + } + + if ( !$paged ) + $paged = 1; + + $nextpage = intval($paged) + 1; + + if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) { + $attr = apply_filters( 'next_posts_link_attributes', '' ); + return '". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .''; + } } /** * Display the next posts pages link. * * @since 0.71 + * @uses get_next_posts_link() * * @param string $label Content for link text. * @param int $max_page Optional. Max pages. */ -function next_posts_link($label='Next Page »', $max_page=0) { - global $paged, $wp_query; - if ( !$max_page ) { - $max_page = $wp_query->max_num_pages; - } - if ( !$paged ) - $paged = 1; - $nextpage = intval($paged) + 1; - if ( (! is_single()) && (empty($paged) || $nextpage <= $max_page) ) { - echo '". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .''; - } +function next_posts_link( $label = 'Next Page »', $max_page = 0 ) { + echo get_next_posts_link( $label, $max_page ); } /** @@ -1111,29 +1133,48 @@ function get_previous_posts_page_link() { } /** - * Display previous posts pages link. + * Display or return the previous posts pages link. * * @since 0.71 + * + * @param boolean $echo Optional. Echo or return; */ -function previous_posts() { - echo clean_url(get_previous_posts_page_link()); +function previous_posts( $echo = true ) { + $output = clean_url( get_previous_posts_page_link() ); + + if ( $echo ) + echo $output; + else + return $output; } /** - * Display previous posts page link. + * Return the previous posts pages link. + * + * @since 2.7.0 + * + * @param string $label Optional. Previous page link text. + * @return string|null + */ +function get_previous_posts_link( $label = '« Previous Page' ) { + global $paged; + + if ( !is_single() && $paged > 1 ) { + $attr = apply_filters( 'previous_posts_link_attributes', '' ); + return '". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&$1', $label ) .''; + } +} + +/** + * Display the previous posts page link. * * @since 0.71 + * @uses get_previous_posts_link() * * @param string $label Optional. Previous page link text. */ -function previous_posts_link($label='« Previous Page') { - global $paged; - if ( (!is_single()) && ($paged > 1) ) { - echo '". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .''; - } +function previous_posts_link( $label = '« Previous Page' ) { + echo get_previous_posts_link( $label ); } /** @@ -1145,7 +1186,7 @@ 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 »') { +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;