Loading...
网友提供的内容

给wordpress增加月度评论之星功能

细心的朋友可能已经发现了,本blog的sidebar上面已经多了一个项目,那就是“本月评论之星”,这个栏目的作用就是将最近一个月在本blog评论最多的网友给显示出来,下面就给出详细方法:

首先在模板的functions.php中增加一个函数:下载

if( !function_exists("u_get_recent_top_commenter")){
	function u_get_recent_top_commenter($num,$size) {

		global $wpdb, $tablecomments;

		$datey = date("Y");

		$datem = date("m")-1;

		if( $datem == 0 ){ $datem = 12; $datey --;}

		$dateold =  $datey."-".$datem."00:00";

		$sql = "SELECT comment_author_email,comment_author, comment_author_url, count( comment_author_email ) AS cmtcount
			FROM  $tablecomments
			WHERE user_id < 1
                        AND  comment_approved =1
			AND comment_type = ''
			AND comment_date > '".$dateold ."'
			GROUP BY comment_author_email
			ORDER BY cmtcount DESC
			LIMIT 0 , ".$num;

		if( $size < 10 ) $size = 10;
		if( $size > 80 ) $size = 80;
		$comments = $wpdb->get_results($sql);
		$output = '';
		foreach ($comments as $comment) {
			$md5email = md5($comment->comment_author_email);
			$commentcomment_author = $comment->comment_author;
			if( strlen( $comment->comment_author_url  ) < 8 ) {$url = "#"; $hint = "#".$comment->comment_author." has no blog yet";}
			else {$url =  $comment->comment_author_url; $hint = "#visit ".$comment->comment_author."' s blog";}
			$src = "http://www.gravatar.com/avatar.php?gravatar_id=".$md5email."&size=".$size ;
			$output .="";
			$output .="$commentcomment_author";

		   }
		   echo $output;
	}
}

在合适的地方调用此函数即可u_get_recent_top_commenter($num,$size),num表示显示最多评论网友的数量,size表示网友头像图标的大小。

由于防止spam评论增加,因此评论网友的url采用javascript打开。

需要增加的一个css是.topcmtor img{border:1px solid #ccc;width:50px;height:50px;margin:2px;padding:2px}
喜欢折腾wordpress的朋友,折腾去吧!

站内评论

  • 暂无评论
昵称: 不能为空
E-mail: email不会被泄露 email格式不正确
评论: 评论不能为空