Opened 13 years ago
Closed 10 years ago
#20319 closed defect (bug) (fixed)
$page value not being defaulted to 1 in the absence of cpage query var in get_next_comments_link()/get_previous_comments_link()
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.2 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Comments | Keywords: | has-patch |
Focuses: | template | Cc: |
Description
get_next_comments_link() generates incorrect comment pagination links on the first page when used alongside a user-made call to wp_list_comments().
Currently, get_next_comments_link() doesn't take into account instances where there is no 'cpage' query var (which is the case when a user-made call to wp_list_comments() is performed). The intval() of the empty $page variable returns 0, and at this point should then be defaulted to 1 in order for the correct link to page 2 to be generated. Instead, it's left as 0, and the resulting link is self-referencing to page 1.
In wp-includes/link-template.php:
function get_next_comments_link( $label = '', $max_page = 0 ) { global $wp_query; if ( !is_singular() || !get_option('page_comments') ) return; $page = get_query_var('cpage'); //RETURNS EMPTY IN ABSENCE OF A cpage VALUE ON PAGE 1 OF A USER-MADE CALL TO wp_list_comments() $nextpage = intval($page) + 1; //intval() RETURNS 0, 0+1=1, RESULTING IN THE "Newer Comments" LINK SELF-REFERENCING PAGE 1, INSTEAD OF POINTING TO PAGE 2 ...
Coincidentally, in paginate_comments_links() (wp-includes/link-template.php) this situation is handled correctly, and $page does get correctly defaulted to 1. The same conditional used in paginate_comments_links() can be applied to both get_next_comments_link() and get_previous_comments_link(). The code to properly account for it is:
function get_next_comments_link( $label = '', $max_page = 0 ) { global $wp_query; if ( !is_singular() || !get_option('page_comments') ) return; $page = get_query_var('cpage'); if ( !$page ) //******** ADDED $page = 1; //******** ADDED $nextpage = intval($page) + 1; //intval() RETURNS 0, 0+1=1, RESULTING IN THE "Newer Comments" LINK NOT POINTING TO PAGE 2 ...
The same addition should be made to get_previous_comments_link() as well, although it's obviously unnoticeable on the first page.
Attachments (2)
Change History (10)
#3
@
10 years ago
- Keywords needs-refresh added
- Milestone changed from Awaiting Review to Future Release
#4
@
10 years ago
- Keywords needs-refresh removed
- Milestone changed from Future Release to 4.2
+1 I have come across this issue as well.
Patch looks good and handles get_previous_comments_link()
as well.
Moving to 4.2 milestone.
#5
@
10 years ago
Thanks!
Patch refresh aims to fix incorrect comment pagination links that arise from lack of a 'cpage' query var.
Also includes some small cleanup.
Looks good, though not a new problem. Likely introduced way before 3.0.