Reputation: 39
I have a problem with WordPress comment template.
I want to sort comments by descending order.
I tried to use this code but it did not work.
array ('order' => 'DESC')
Comment Template:
<div class="wpcomments">
<?php if(comments_open()) : ?>
<div class="commentstyle">
<?php if(!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) : ?>
<?php die('You can not access this page directly!'); ?>
<?php endif; ?>
<?php if(!empty($post->post_password)) : ?>
<?php if($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) : ?>
<p>This post is password protected. Enter the password to view comments.</p>
<?php endif; ?>
<?php endif; ?>
<?php if($comments) : ?>
<ol>
<?php foreach($comments as $comment) : ?>
<li id="comment-<?php comment_ID(); ?>">
<div class="commentw">
<?php if ($comment->comment_approved == '0') : ?>
<p></p>
<?php endif; ?>
<div class="comment-avatar"></div>
<div class="comment-left"><b><?php comment_author_link(); ?></b> (<?php comment_date(); ?> <?php comment_time(); ?>)
<div class="comment-below">
<?php comment_text(); ?>
</div>
</div>
</div>
</li>
<?php endforeach; ?>
</ol>
<?php else : ?>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
Upvotes: 2
Views: 1929
Reputation: 846
It can be done by admin dashboard or SQL:
// SELECT * FROM wp_options WHERE option_name LIKE '%comment%'
UPDATE wp_options SET option_value='desc' WHERE option_name='comment_order'
Upvotes: 3
Reputation: 3614
Try
'comments_array' hook in function.php
add_filter( 'comments_array' , 'shuffle_comments' , 10, 2 );
function shuffle_comments( $comments , $post_id ){
return shuffle( $comments );
}
for modify your result for particular post,
Upvotes: 2