From ae65f5197c1b300b647268754a033a2828cbbf49 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 7 Oct 2008 22:41:51 +0000 Subject: [PATCH] paginate_comments_links(). see #7769 git-svn-id: http://svn.automattic.com/wordpress/trunk@9097 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/general-template.php | 6 ++++- wp-includes/link-template.php | 44 +++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 426e958b6..40b84dcc5 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[] = ""; 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[] = ""; endif; switch ( $type ) : diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index cd149e62e..c10e4c83c 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,