Typecho评论调用QQ头像以及随机头像教程
摘要
Typecho评论时,默认调用的Gravatar头像,但是Gravatar被墙了,导致评论区总会有很多Gravatar默认头像G,特别不美观。所以,把我的typecho评论头像修改教程分享给大家。
原理
当用户评论时,该代码会自行判断所填邮箱是qq邮箱还是其他邮箱。qq邮箱会调用qq头像,而其他的邮箱则默认随机头像(可自行设置其他头像图片)。
教程
在主题下的comments.php文件中,查找关键字gravatar,将
<?php $comments->gravatar('40', ''); ?>
替换为
<?php $number=$comments->mail;
if(preg_match('|^[1-9]\d{4,[email protected]\.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" alt="<?php echo $comments->author; ?>" height="50" width="50" class="avatar avatar-50 photo"/>';
}else{
echo '<img src="https://www.icnal.com/sjtx/api.php" height="50" width="50" class="avatar avatar-50 photo"/>';
}
?>
即可,上面的随机头像API是我自己搭建使用的,可以直接使用或者看我的超简单的随机头像API搭建教程。
新增更新
为博主邮箱增加识别,如果你自己用的QQ邮箱,用上面的代码就好,如果是像我一样的域名邮箱,最好用下面代码给自己来个固定头像!
<?php $number=$comments->mail;
if(preg_match('|^[1-9]\d{4,[email protected]\.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" alt="评论者头像" height="50" width="50" class="avatar avatar-50 photo"/>';
}
elseif (preg_match('|^[a-z]{4,[email protected]\.com$|i',$number)) {
echo '<img src="https://www.icnal.com/images/toux.jpg" height="50" width="50" class="avatar avatar-50 photo" alt="评论者头像"/>';
}
else{
echo '<img src="https://www.icnal.com/sjtx/api.php" height="50" width="50" class="avatar avatar-50 photo" alt="评论者头像"/>';
}
?>
注:有的主题<?php $comments->gravatar('40', ''); ?>
被修改过了,具体修改可以自己F12查看头像位置,有不会的可以联系我,有空会免费教的。