From cf2730334f8df2183920d12431caa1ae7bc697d7 Mon Sep 17 00:00:00 2001 From: markjaquith Date: Fri, 24 Oct 2008 07:36:43 +0000 Subject: [PATCH] Enable pretty permalinks for previous_ and next_comments_link(). props DD32, Viper007Bond. see #7942 git-svn-id: http://svn.automattic.com/wordpress/trunk@9318 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/canonical.php | 2 +- wp-includes/link-template.php | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index 58acf379a..a9b4af11d 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -149,7 +149,7 @@ function redirect_canonical($requested_url=null, $do_redirect=true) { if ( is_feed() ) { $paged_redirect['path'] = user_trailingslashit( trailingslashit( $paged_redirect['path'] ) . 'feed/' . ( ( 'rss2' == get_query_var('feed') || 'feed' == get_query_var('feed') ) ? '' : get_query_var('feed') ), 'feed' ); } - if ( get_query_var('cpage') > 1 ) { + if ( ( 'newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 ) || ( 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1 ) ) { $paged_redirect['path'] = user_trailingslashit( trailingslashit( $paged_redirect['path'] ) . 'comment-page-' . get_query_var('cpage'), 'commentpaged' ); } $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path']; diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 1348145cd..5efe57a83 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -1148,16 +1148,25 @@ function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { $request = preg_replace('|^'. $home_root . '|', '', $request); $request = preg_replace('|^/+|', '', $request); + $request = preg_replace('|comment-page-[0-9]+/?$|', '', $request); $base = trailingslashit( get_bloginfo( 'home' ) ); $result = $base . $request; if ( 'newest' == get_option('default_comments_page') ) { - if ( $pagenum != $max_page ) + if ( $pagenum != $max_page ) { + if ( $wp_rewrite->using_permalinks() ) + $result = user_trailingslashit( trailingslashit($base . $request) . 'comment-page-' . $pagenum, 'commentpaged'); + else + $result = add_query_arg( 'cpage', $pagenum, $base . $request ); + } + } elseif ( $pagenum > 1 ) { + if ( $wp_rewrite->using_permalinks() ) + $result = user_trailingslashit( trailingslashit($base . $request) . 'comment-page-' . $pagenum, 'commentpaged'); + else $result = add_query_arg( 'cpage', $pagenum, $base . $request ); - } elseif ( $pagenum > 1 ) - $result = add_query_arg( 'cpage', $pagenum, $base . $request ); + } $result .= '#comments'; @@ -1181,7 +1190,7 @@ function next_comments_link($label='', $max_page = 0) { return; $page = get_query_var('cpage'); - + if ( !$page ) $page = 1; @@ -1209,7 +1218,6 @@ function next_comments_link($label='', $max_page = 0) { * @param string $label Optional. Label for comments link text. */ function previous_comments_link($label='') { - global $wp_query; if ( !is_singular() ) return; @@ -1222,12 +1230,12 @@ function previous_comments_link($label='') { if ( $page <= 1 ) return; - $nextpage = intval($page) - 1; + $prevpage = intval($page) - 1; if ( empty($label) ) $label = __('« Older Comments'); - echo '". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .''; }