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.

0 down vote favorite

I have a wordpress single post where I have comment system - Live Site

And I have two links one is: 1. newest 2. oldest

The thing I want is when I will click on newest it will display the comments list in newest order and if I click on oldest it will display the comments list from oldest to newest.

Any simple solution is fine (though I prefer using ajax but no need for ajax right now). GET and POST method will be fine.

Any clue?

Thanks in adavance

share|improve this question
    
see the live site: oryxtesting.com/events/teaching-event –  user17111 Aug 19 '12 at 11:33
add comment

1 Answer 1

up vote 0 down vote accepted

Just open the comments.php file from your theme. Find the following line (or similar)

<?php foreach ($comments as $comment) : ?>

Add this lines just above it

if (isset($_GET['comOrder']) && $_GET['comOrder'] == 'Newest' )
    $comments = array_reverse($comments, true);

so your code looks like this:

<?php if (isset($_GET['comOrder']) && $_GET['comOrder'] == 'Newest' )
        $comments = array_reverse($comments, true);
foreach ($comments as $comment) : ?>

and then make sure your newest first like points to your current location with ?comOrder=Newest

UPDATE:

In case you are using wp_list_comments then simply add reverse_top_level parameter set to true when newest first link is clicked so something like this should work:

$args = array('type' =>'comments','callback' => 'mytheme_comment');
if (isset($_GET['comOrder']) && $_GET['comOrder'] == 'Newest' )
    $args['reverse_top_level'] = true;
wp_list_comments($args);
share|improve this answer
    
well, thanks for that, but i dont have foreach, i have wp_list_comments('type=comments&callback=mytheme_comment'). mytheme_comment is my customised function in functions.php file. So should i put your code before that wp_list_comments function? –  user17111 Aug 19 '12 at 13:18
    
updated my answer –  Bainternet Aug 19 '12 at 13:35
    
i did use your last updae but still not working. is it something wrong in my mytheme_comment function ? is it possible for you to login to wp site and have a look at the code? :) –  user17111 Aug 19 '12 at 13:41
    
i dont mind to pay :) –  user17111 Aug 19 '12 at 13:58
    
sorry man its working. i put 'comments' in parameter, it should be 'comment'. thanks man. but now how about displaying comments in oldest to newest ? –  user17111 Aug 19 '12 at 14:04
show 1 more 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.