Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use Wordpress commment pagination as follows:

  • paginated comments
  • comments displayed with the newest comments at the top of each page
  • 50 comments on each page
  • first page displayed by default

The problem is that I am trying to achieve YouTube like comments such as - newest comments on first page, first page being displayed by default, then older comments in order on page 2, 3 etc

The problem is that Wordpress comments are structured in such way,that I cannot achieve this by changing the "Discussion" settings.

I have tried different options, such as extending the Walker's paged_walk() function, or to reverse the comments, or even pulling the comments with a MySQL query and using paginate_link() - but can't seem to be able to achieve this type of comments hierarchy.

Any advice is appreciated, thank you!

Solution:

I have found a solution as follows:

  • into functions.php I have inserted a custom function that sorts the comments by date (newest comments first) by using an associative array sorting as can be seen here
  • into the Wordpress settings I changed the following at Settings -> Discussion Comments should be displayed with the comments at the top of each page

So now my comments are being displayed newest first (at top) with page numbering starting from 1.

The only issue that I see, is that when posting a comment the user is redirected for some reason to the last page of comments.

share|improve this question
    
Please add your solution as real answer, then mark the question as answered. If you don’t … I’ll do it. :) –  toscho Jul 10 '12 at 21:51
add comment

1 Answer

A simple way to arrange your comments by most recent is to add this to your functions.php file:

if (!function_exists('custom_reverse_comments')) {
    function custom_reverse_comments($comments) {
        return array_reverse($comments);
    }   
}
add_filter ('comments_array', 'custom_reverse_comments');
share|improve this answer
    
Thanks for the reply ! I used something similar in my solution to this, please see my edit above. –  Iulita Aug 23 '11 at 16:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.