让wordpress最新评论不显示管理员评论的简单方法
wordpress默认会在侧边栏的最新评论显示出你自己回复的评论。我觉得这样很不好,占了最新评论那里宝贵的地理位置。
侧边栏的最新评论寸土寸金,怎能让博主自己的评论回复去玷污它呢?所以,必除之。
用插件?不爽。为了体现至高无尚的折腾精神,还是自己改代码吧:
在function.php或sidebar.php里找到如果代码块
<?php
function recent_comment($comment_nums = 20) {global $wpdb;$sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = ‘1′ AND comment_type = ” AND post_password = ” AND user_id !=1 ORDER BY comment_date_gmt DESC LIMIT $comment_nums”;
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
foreach ($comments as $comment) {
$output .= “\n<li>”. “<a href=\”” . get_permalink($comment->ID) . “#comment-” . $comment->comment_ID . “\” title=\””.
$comment->post_title . “\”>” . strip_tags($comment->com_excerpt) .”</a></li>”;}$output .= $post_HTML;
echo $output;
}?>
红色之处就是需要添加的代码。
ok!