最新评论、留言不显示管理员的言论

林继 WordPress 2,333 共写了95个字 (2010-08-21 9:41:44) 没有评论 打印 扫描二维码 百度已收录

出处:Hacklog【荒野无灯weblog
在SQL查询语句里增加 AND user_id !=1 ,这个ID是管理员的,可以在这里查看。

  1.  //最新评论、留言
  2. function recent_comment( $comment_post_ID=0, $get_total=5, $show_author_url=1, $before='<li>', $after='</li>') {
  3. 	global $wpdb;
  4. 	$is_gb =($comment_post_ID == "0") ? " != 'guestbook' " : " = 'guestbook' ";
  5. 	$request="SELECT ID, post_name, comment_ID, comment_content, comment_author_email, comment_author, comment_author_url, comment_date, post_title FROM $wpdb->comments ";
  6. 	$request .= " LEFT JOIN $wpdb->posts ON $wpdb->posts.ID=$wpdb->comments.comment_post_ID ";
  7. 	$request .= " WHERE post_status IN ('publish','static') AND comment_approved='1' AND $wpdb->posts.post_name ".$is_gb."  AND user_id !=1 ORDER BY comment_ID DESC LIMIT $get_total";
  8. 	$comments=$wpdb->get_results($request);
  9. 	if ($comments) {
  10. 		foreach ($comments as $comment) {
  11. 			$email=$comment->comment_author_email;
  12. 			$grav_url="http://www.gravatar.com/avatar/".md5($email)."?s=32";
  13. 			$comment_author=stripslashes(strip_tags($comment->comment_author));
  14. 			$comment_content=utf8Substr(stripslashes(strip_tags($comment->comment_content)),0,150);
  15. 			if ($show_author_url == 1 && strlen($comment->comment_author_url) > 12) $comment_author='<a target="_blank" title="访问 '.$comment_author. '的网站" href="' . $comment->comment_author_url . '">' . $comment_author . '</a>';
  16. 			$post_title=stripslashes($comment->post_title);
  17. 			$comment_date=date("y-m-d H:i",strtotime($comment->comment_date));
  18. 			$permalink=get_permalink($comment->ID)."#comment-".$comment->comment_ID;
  19.  
  20. 			$output=$before."\n";
  21. 			$output .= '<span class="avatar"><img src="'.$grav_url.'" alt="" /></span>'."\n";
  22. 			$output .= '<span class="fn">'.$comment_author.'</span>'."\n";
  23. 			$output .= '<span class="date">'.$comment_date.'</span>'."\n";
  24. 			$output .= '<span class="txt"><a href="'.$permalink.'" title="'.$post_title.' &raquo; '.$comment_content.'">'.$comment_content.'</a></span>'."\n";
  25. 			$output .= $after."\n";
  26. 			echo $output."\n";
  27. 		}
  28. 	}
  29. }

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注

< >