几天前,我为朋友的一个WordPress站点做了一个小小的改动,他想要让最新添加的评论显示在评论列表的最上面,而默认的WordPress是显示在列表底部的。 如果你也需要这项功能的话, 那么只需要对/wp-includes/comment-template.php文件做一些小小的改动就可以了。
原来的代码:
// TODO: Use API instead of SELECTs.
if ( $user_ID) {
$comments = $wpdb->get_results(“SELECT * FROM $wpdb->comments WHERE comment_post_ID = ‘$post->ID’ AND (comment_approved = ’1′ OR ( user_id = ‘$user_ID’ AND comment_approved = ’0′ ) ) ORDER BY comment_date”);
} else if ( empty($comment_author) ) {
$comments = $wpdb->get_results(“SELECT * FROM $wpdb->comments WHERE comment_post_ID = ‘$post->ID’ AND comment_approved = ’1′ ORDER BY comment_date”);
} else {
$author_db = $wpdb->escape($comment_author);
$email_db = $wpdb->escape($comment_author_email);
$comments = $wpdb->get_results(“SELECT * FROM $wpdb->comments WHERE comment_post_ID = ‘$post->ID’ AND ( comment_approved = ’1′ OR ( comment_author = ‘$author_db’ AND comment_author_email = ‘$email_db’ AND comment_approved = ’0′ ) ) ORDER BY comment_date”);
}
你所需要做的就是加四个字母… DESC :
// TODO: Use API instead of SELECTs.
if ( empty($comment_author) ) {
$comments = $wpdb->get_results(”SELECT * FROM $wpdb->comments WHERE comment_post_ID = ‘$post->ID’ AND comment_approved = ‘1′ ORDER BY comment_date DESC“);
} else {
$author_db = $wpdb->escape($comment_author);
$email_db = $wpdb->escape($comment_author_email);
$comments = $wpdb->get_results(”SELECT * FROM $wpdb->comments WHERE comment_post_ID = ‘$post->ID’ AND ( comment_approved = ‘1′ OR ( comment_author = ‘$author_db’ AND comment_author_email = ‘$email_db’ AND comment_approved = ‘0′ ) ) ORDER BY comment_date DESC“);
}
OK,就是这样了, 我用Dreamweaver修改的时候特意留意了一下, 这些代码可以在290行左右找到这些代码。