编程技术

Typecho评论头像改QQ头像或者随机小姐姐

# 实现

  • typecho评论默认显示的头像是Gravatar头像,我想改成这样的:

如果是QQ邮箱,就显示QQ头像,

如果不是,就使用随机头像。

# 在模板的comments.php文件中搜索gravatar

上面标记的那行替换成下面的代码

<span itemprop="image"><?php $number=$comments->mail;
if(preg_match('|^[1-9]\d{4,11}@qq\.com$|i',$number)){
echo '<img src="https://q2.qlogo.cn/headimg_dl? bs='.$number.'&dst_uin='.$number.'&dst_uin='.$number.'&;dst_uin='.$number.'&spec=100&url_enc=0&referer=bu_interface&term_type=PC" width="46px" height="46px" style="border-radius: 50%;float: left;margin-top: 0px;margin-right: 10px;margin-bottom:-2px">'; 
}else{
echo '<img src="https://uploadbeta.com/api/pictures/random/?key=%e6%a0%a1%e5%9b%ad" width="46px" height="46px" style="border-radius: 50%;float: left;margin-top: 0px;margin-right: 10px;margin-bottom:-2px">';
}
?>
</span>
1
2
3
4
5
6
7
8

刷新页面,提交评论,就可以看到效果了。 上面的代码中的https://upload*****ture是调用的接口。