diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php
index 426e958b6c..40b84dcc50 100644
--- a/wp-includes/general-template.php
+++ b/wp-includes/general-template.php
@@ -1633,7 +1633,8 @@ function paginate_links( $args = '' ) {
'end_size' => 1,
'mid_size' => 2,
'type' => 'plain',
- 'add_args' => false // array of query args to add
+ 'add_args' => false, // array of query args to add
+ 'add_fragment' => ''
);
$args = wp_parse_args( $args, $defaults );
@@ -1657,6 +1658,7 @@ function paginate_links( $args = '' ) {
$link = str_replace('%#%', $current - 1, $link);
if ( $add_args )
$link = add_query_arg( $add_args, $link );
+ $link .= $add_fragment;
$page_links[] = "$prev_text";
endif;
for ( $n = 1; $n <= $total; $n++ ) :
@@ -1669,6 +1671,7 @@ function paginate_links( $args = '' ) {
$link = str_replace('%#%', $n, $link);
if ( $add_args )
$link = add_query_arg( $add_args, $link );
+ $link .= $add_fragment;
$page_links[] = "$n";
$dots = true;
elseif ( $dots && !$show_all ) :
@@ -1682,6 +1685,7 @@ function paginate_links( $args = '' ) {
$link = str_replace('%#%', $current + 1, $link);
if ( $add_args )
$link = add_query_arg( $add_args, $link );
+ $link .= $add_fragment;
$page_links[] = "$next_text";
endif;
switch ( $type ) :
diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php
index cd149e62ee..c10e4c83c4 100644
--- a/wp-includes/link-template.php
+++ b/wp-includes/link-template.php
@@ -815,6 +815,8 @@ function get_comments_pagenum_link($pagenum = 1) {
$result = $base . $request;
}
+ $result .= '#comments';
+
$result = apply_filters('get_comments_pagenum_link', $result);
return $result;
@@ -828,9 +830,6 @@ function next_comments_link($label='', $max_page = 0) {
$page = get_query_var('cpage');
- if ( !$page )
- $page = 1;
-
if ( !$page )
$page = 1;
@@ -858,6 +857,9 @@ function previous_comments_link($label='') {
$page = get_query_var('cpage');
+ if ( !$page )
+ $page = 1;
+
if ( $page <= 1 )
return;
@@ -871,6 +873,42 @@ function previous_comments_link($label='') {
echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'';
}
+/** Create pagination links for the comments on the current post
+ *
+ * @package WordPress
+ * @see paginate_links
+ * @since 2.7
+ *
+ * @param string|array $args Optional args. See paginate_links.
+ * @return string Markup for pagination links
+*/
+function paginate_comments_links($args = array()) {
+ global $wp_query;
+
+ if ( !is_singular() )
+ return;
+
+ $page = get_query_var('cpage');
+ if ( !$page )
+ $page = 1;
+ $max_page = $wp_query->max_num_comment_pages;
+ $defaults = array(
+ 'base' => add_query_arg( 'cpage', '%#%' ),
+ 'format' => '',
+ 'total' => $max_page,
+ 'current' => $page,
+ 'echo' => true,
+ 'add_fragment' => '#comments'
+ );
+ $args = wp_parse_args( $args, $defaults );
+ $page_links = paginate_links( $args );
+
+ if ( $args['echo'] )
+ echo $page_links;
+ else
+ return $page_links;
+}
+
function get_shortcut_link() {
$link = "javascript:
var d=document,