Typecho基于评论数的评论等级

Typecho基于评论数的评论等级

Laoyao
2020-09-29 / 13 评论 / 5,275 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年12月24日,已超过859天没有更新,若内容或图片失效,请留言反馈。

今天发现了一个 Typecho 的评论等级,感觉很有意思就特地的分享出来了。
代码
[hide]

function dengji($i){
$db=Typecho_Db::get();
$mail=$db->fetchAll($db->select(array('COUNT(cid)'=>'rbq'))->from('table.comments')->where('mail = ?', $i)->where('authorId = ?','0'));
foreach ($mail as $sl){
$rbq=$sl['rbq'];}
if($rbq<1){
echo 'Boss';
}elseif ($rbq<5 && $rbq>0) {
echo '朋友';
}elseif ($rbq<10 && $rbq>=5) {
echo '游客';
}elseif ($rbq<15 && $rbq>=10) {
echo '游客1';
}elseif ($rbq<20 && $rbq>=15) {
echo '游客2';
}elseif ($rbq<25 && $rbq>=20) {
echo '游客3';
}elseif ($rbq>=25) {
echo '游客4';
}
}

[/hide]

使用方法

将以上代码加到functions.php里,然后在comments.php里找到如下位置(可能有的主题不一样):

<span class=" <?php echo $commentAuthor; ?> "><?php $comments->author(false); ?>:</span>
<?php dengji($comments->mail);?> 

在评论列表循环里加上这个引用,也就是这样:

<span class=" <?php echo $commentAuthor; ?> ">【<?php dengji($comments->mail);?>】<?php $comments->author(false); ?>:</span>

报错
如果博主称号显示不是Boss而是游客,那么请在Mysql里执行如下:

update typecho_comments set authorid='1' where mail='博主邮箱账号'
8

评论

博主关闭了当前页面的评论