Make WordPress Core

Changeset 9632


Ignore:
Timestamp:
11/12/2008 10:13:50 AM (18 years ago)
Author:
azaozz
Message:

Fixes for previous/next page links, props Viper007Bond, fixes #8058

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/link-template.php

    r9415 r9632  
    10551055
    10561056/**
    1057  * Display the next posts pages link.
     1057 * Display or return the next posts pages link.
    10581058 *
    10591059 * @since 0.71
    10601060 *
    10611061 * @param int $max_page Optional. Max pages.
    1062  */
    1063 function next_posts($max_page = 0) {
    1064         echo clean_url(get_next_posts_page_link($max_page));
    1065 }
    1066 
    1067 /**
    1068  * Display the next posts pages link.
    1069  *
    1070  * @since 0.71
     1062 * @param boolean $echo Optional. Echo or return;
     1063 */
     1064function next_posts( $max_page = 0, $echo = true ) {
     1065        $output = clean_url( get_next_posts_page_link( $max_page ) );
     1066
     1067        if ( $echo )
     1068                echo $output;
     1069        else
     1070                return $output;
     1071}
     1072
     1073/**
     1074 * Return the next posts pages link.
     1075 *
     1076 * @since 2.7.0
    10711077 *
    10721078 * @param string $label Content for link text.
    10731079 * @param int $max_page Optional. Max pages.
    1074  */
    1075 function next_posts_link($label='Next Page »', $max_page=0) {
     1080 * @return string|null
     1081 */
     1082function get_next_posts_link( $label = 'Next Page »', $max_page = 0 ) {
    10761083        global $paged, $wp_query;
     1084
    10771085        if ( !$max_page ) {
    10781086                $max_page = $wp_query->max_num_pages;
    10791087        }
     1088
    10801089        if ( !$paged )
    10811090                $paged = 1;
     1091
    10821092        $nextpage = intval($paged) + 1;
    1083         if ( (! is_single()) && (empty($paged) || $nextpage <= $max_page) ) {
    1084                 echo '<a href="';
    1085                 next_posts($max_page);
     1093
     1094        if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) {
    10861095                $attr = apply_filters( 'next_posts_link_attributes', '' );
    1087                 echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
    1088         }
     1096                return '<a href="' . next_posts( $max_page, false ) . "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
     1097        }
     1098}
     1099
     1100/**
     1101 * Display the next posts pages link.
     1102 *
     1103 * @since 0.71
     1104 * @uses get_next_posts_link()
     1105 *
     1106 * @param string $label Content for link text.
     1107 * @param int $max_page Optional. Max pages.
     1108 */
     1109function next_posts_link( $label = 'Next Page &raquo;', $max_page = 0 ) {
     1110        echo get_next_posts_link( $label, $max_page );
    10891111}
    10901112
    … …  
    11121134
    11131135/**
    1114  * Display previous posts pages link.
     1136 * Display or return the previous posts pages link.
    11151137 *
    11161138 * @since 0.71
    1117  */
    1118 function previous_posts() {
    1119         echo clean_url(get_previous_posts_page_link());
    1120 }
    1121 
    1122 /**
    1123  * Display previous posts page link.
     1139 *
     1140 * @param boolean $echo Optional. Echo or return;
     1141 */
     1142function previous_posts( $echo = true ) {
     1143        $output = clean_url( get_previous_posts_page_link() );
     1144
     1145        if ( $echo )
     1146                echo $output;
     1147        else
     1148                return $output;
     1149}
     1150
     1151/**
     1152 * Return the previous posts pages link.
     1153 *
     1154 * @since 2.7.0
     1155 *
     1156 * @param string $label Optional. Previous page link text.
     1157 * @return string|null
     1158 */
     1159function get_previous_posts_link( $label = '&laquo; Previous Page' ) {
     1160        global $paged;
     1161
     1162        if ( !is_single() && $paged > 1 ) {
     1163                $attr = apply_filters( 'previous_posts_link_attributes', '' );
     1164                return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label ) .'</a>';
     1165        }
     1166}
     1167
     1168/**
     1169 * Display the previous posts page link.
    11241170 *
    11251171 * @since 0.71
     1172 * @uses get_previous_posts_link()
    11261173 *
    11271174 * @param string $label Optional. Previous page link text.
    11281175 */
    1129 function previous_posts_link($label='&laquo; Previous Page') {
    1130         global $paged;
    1131         if ( (!is_single())     && ($paged > 1) ) {
    1132                 echo '<a href="';
    1133                 previous_posts();
    1134                 $attr = apply_filters( 'previous_posts_link_attributes', '' );
    1135                 echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
    1136         }
     1176function previous_posts_link( $label = '&laquo; Previous Page' ) {
     1177        echo get_previous_posts_link( $label );
    11371178}
    11381179
    … …  
    11461187 * @param string $nxtlabel Optional Label for next pages.
    11471188 */
    1148 function posts_nav_link($sep=' &#8212; ', $prelabel='&laquo; Previous Page', $nxtlabel='Next Page &raquo;') {
     1189function posts_nav_link( $sep = ' &#8212; ', $prelabel = '&laquo; Previous Page', $nxtlabel = 'Next Page &raquo;' ) {
    11491190        global $wp_query;
    11501191        if ( !is_singular() ) {
Note: See TracChangeset for help on using the changeset viewer.