Opened 17 years ago
Closed 17 years ago
#4297 closed enhancement (wontfix)
Order Comments
Reported by: | hyp0r | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | |
Component: | General | Keywords: | sort comments order by |
Focuses: | Cc: |
Description
Allow comments to by sorted in descending order.
On some pages on my site I like to list comments with the newest comment on top. Every time that I upgrade I have to make these changes to the comment-template.php
line 280:
add , $order = 'ASC' to the comments_template function:
function comments_template( $file = '/comments.php', $order = 'ASC' ) {
line 292, 294 & 298:
add $order after ORDER BY comment_date
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND (comment_approved = '1' OR ( user_id = '$user_ID' AND comment_approved = '0' ) ) ORDER BY comment_date $order");
With the above modifications the code will continue to work exactly the way it does now. But you can use this code:
<?php comments_template('/comments.php','DESC'); ?>
and it will display the comments in descending order.
I don't see any reason that this would cause any problems. I'd love to help add this feature (it's quite simple). I'm not sure how to do that, if someone could point me in the right direction I'd love to help out.
Attachments (1)
Change History (8)
#5
in reply to:
↑ 4
@
17 years ago
Replying to filosofo:
The comments get passed through the 'comments_array' filter, so you should be able to use a callback function to re-sort them then.
Can you please explain the 'comments_array' filter to me? I'm not familiar with how that works.
#6
@
17 years ago
You can read about plugin filters here.
Before the comments_template function prints the comments template, it filters the comments through the comments_array filter.
function sort_my_comments($comments) {
[do sorting]
return $comments;
}
add_filter('comments_array','sort_my_comments');
The comments get passed through the 'comments_array' filter, so you should be able to use a callback function to re-sort them then.