Latest Updated:无需修改源代码即可以实现评论显示倒序。在评论模板comments.php中找到下列语句: 

<?php if ($comments) : ?>

在其后面添加上让评论倒序的代码:

<?php $comments = array_reverse($comments) ?> 

谢谢Zhang

*************************

Wordpress默认的评论(留言)顺序是按照时间顺序升序来显示的,这样最新的评论会被显示在最下面,比较不符合阅读习惯(或者说是不符合我的阅读习惯吧)。通过更改comments_template的代码可以实现降序显示评论,从而将最新的评论显示在最前面。

进入Wordpress安装目录下的wp-includes目录,用文本编辑器打开comment-template.php文件,找到如下代码:

$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date");

在“ORDER BY comment_date”后面加上“DESC”, 

$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date DESC");

保存退出,即可。这样评论的显示顺序就被改为以时间降序来显示了。

注:请将if else里面的3条get_results都加上DESC。 

本方法在wordpress2.1、2.2中测试通过。

Feed Me


转载文章请注明转载自:ThinkAgain - Let's Blog!

引用地址:http://www.thinkagain.cn/archives/147.html