我的WordPress评论模板有问题。
我想按降序排序评论。
我尝试使用此代码,但它无效。
array ('order' => 'DESC')
评论模板:
<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>
答案 0 :(得分:1)
尝试
'comments_array' hook in function.php
add_filter( 'comments_array' , 'shuffle_comments' , 10, 2 );
function shuffle_comments( $comments , $post_id ){
return shuffle( $comments );
}
修改特定帖子的结果,
答案 1 :(得分:0)
可以通过UI或SQL完成:
// SELECT * FROM wp_options WHERE option_name LIKE '%comment%'
UPDATE wp_options SET option_value='desc' WHERE option_name='comment_order'