EMLOG学院

获取最近留言访客头像函数

摘要: 刚才写个模板需要在底部加一个最新访...

刚才写个模板需要在底部加一个最新访客,顺手写了个函数,需要的可以借鉴借鉴

/**
 * 获取Gravatar头像
 */
function getGravatar_fk($email, $s = 40, $d = 'mm', $g = 'g') {
	$hash = md5($email);
	$avatar = "http://gravatar.duoshuo.com/avatar/$hash?s=$s&d=$d&r=$g";
	return $avatar;
}
//获取最新评论访客
function comment($num){
	$t = MySql::getInstance();
	$sql = "SELECT * FROM ".DB_PREFIX."comment WHERE mail != '' ORDER BY `cid` DESC LIMIT $num";
	$list = $t->query($sql);
	while($row = $t->fetch_array($list)){
		$i = '<li><a rel="nofollow" href="'.$row['url'].'"><img src="'.getGravatar_fk($row['mail']).'"></a></li>';
		echo $i;
	}
}
使用方式:

comment($num) //$num为调用数量

发表评论:

评论(0)