Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#8168 closed defect (bug) (fixed)

Using "type" parameter on wp_list_comments() screws up paging

Reported by: Viper007Bond Owned by: Viper007Bond
Milestone: 2.7 Priority: normal
Severity: normal Version: 2.7
Component: Comments Keywords:
Focuses: Cc:
PR Number:


Who It Affects:

Those who use comment paging and either set the type parameter on wp_list_comments() or pass a custom $comments to that function.

Everyone else (for example, the default theme) is unaffected.

What Happens And Why:

If you have the latest/newest comments page set to show by default, it can show up as blank. For example, if you have 22 comments (2 of which are pings), 5 comments per page, and do wp_list_comments( array( 'type' => 'comment' ) ), you'd end up with 4 pages and the 5th page (which should no longer exist) being blank. get_comment_pages_count() is at fault here as it's using the wrong total comments number when diving total comments by comments per page. If you have the oldest page set as the default, next/previous_comments_link() is smart enough (apparently) to not continue on to the next page.

get_comment_link() also ends up using the wrong page number as it's expecting comments to be displayed that aren't. get_page_of_comment() is at fault here as it's SQL query is grabbing comments that we've excluded.


I spent an hour or two on this last night. Basically what I've been doing is passing along $args to the other various functions. This way they can realize what's going on and account for it.

Attachments (1)

8168.patch (3.3 KB) - added by Viper007Bond 11 years ago.

Download all attachments as: .zip

Change History (8)

#1 @Viper007Bond
11 years ago

  • Keywords needs-patch removed

Forgot to actually mention that I'm not done with the patch yet, but I thought I'd open the ticket to make people aware of the issues and that I'm working on the patch.

Hoping to get this into 2.7.

11 years ago

#2 @Viper007Bond
11 years ago

  • Milestone changed from 2.8 to 2.7

8168.patch should make paging work properly if you pass a type parameter or a $comments to wp_list_comments().

However, doing either of the aforementioned things will break get_comment_link() if used outside of the comment loop as the $page parameter is not passed to it and it therefore gets the page number wrong (due to "missing" comments).

#3 @Viper007Bond
11 years ago

Oh, and get_comment_link() will also break on custom themes using a callback function if they forget to pass $page to it as well.

#4 @jeremyclark13
11 years ago

This is probably along the same lines if not I'll open a new ticket, but the comment_reply_link function doesn't work either when it's used in a callback. I've applied the patch to see if it would help but it doesn't. I'm also not exactly sure how to pass the $page to this function either.

#5 @Viper007Bond
11 years ago

<?php echo get_comment_link( $comment->comment_ID, $args['page'] ); ?>

Might be worth making it automatic via a global or something.

#6 @Viper007Bond
11 years ago

Oh, sorry, wrong function. Not sure about comment_reply_link(). It doesn't deal with paging as far as I'm aware.

#7 @ryan
11 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [9667]) wp_list_comments() fixes when passing type. Props Viper007Bond. fixes #8168

Note: See TracTickets for help on using tickets.