1. 我们先在function.php里面添加一个开关
$JactiveUsers = new Typecho_Widget_Helper_Form_Element_Radio(
'JactiveUsers',
array(
1 => '开启',
0 => '关闭',
),0,'是否开启互动读者','介绍:显示评论相关用户'
);
$JactiveUsers->setAttribute('class', 'j-setting-content j-setting-aside');
$form->addInput($JactiveUsers);
2. 然后我们可以给侧栏加代码了
aside.php 里面对应位置添加,位置和其他啥广告位的一样不多说
<!--互动读者-->
<?php if ($this->options->JactiveUsers and $this->is('index')): ?>
<section class="aside aside-hunter-authors">
<h3 class="aside-title"><i class="icon iconfont icon-wodeguanzhu"></i>
<span><?php _e('互动读者'); ?></span></h3>
<div class="hunter-cont">
<ul class="hunter-authors">
<?php
$period = time() - 2592000; // 单位: 秒, 时间范围: 30天
$counts = Typecho_Db::get()->fetchAll(Typecho_Db::get()
->select('COUNT(author) AS cnt', 'author', 'max(authorId) authorId', 'max(mail) mail')
->from('table.comments')
->where('created > ?', $period)
->where('status = ?', 'approved')
->where('type = ?', 'comment')
->group('author')
->order('cnt', Typecho_Db::SORT_DESC)
->limit('4')
);
$mostactive = '';
$viphonor = Helper::options()->themeUrl('assets/img/authen.svg','Typecho-Joe-Theme');
foreach ($counts as $count) {
$imgUrl = ParseAvatar($count['mail'],1);
if ($count['authorId'] == '0') {
$c_url = '<li><div class="item"><div class="hunter-avatar"><div class="vatar"><img src="' . $imgUrl . '"></div></div><div class="item-main"><div>' . $count['author'] . '';
} else {
$c_url = '<li><div class="item"><div class="hunter-avatar"><a href="' . $this->options->siteUrl . 'index.php/author/' . $count['authorId'] . '" ><div class="vatar"><img src="' . $imgUrl . '"><img class="va_v_honor" src="' . $viphonor . '" title="认证用户"></div></a></div><div class="item-main">' . $count['author'] . '';
}
echo '' . $c_url . '';
autvip($count['mail']);
$allpostnum = allpostnum($count['authorId']);
echo ' <h4>评论 ' . $count['cnt'] . ' 次 | <i>'.$allpostnum.'</i>';
echo ' </h4></div></div></li>';
} ?>
</ul>
</div>
</section>
<?php en#dif; ?>
3. 我们在functions.php 或者 core.php 添加一些辅助函数函数函数加一些辅助函数数
/**
* 显示用户等级,按邮箱
*/
function autvip($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 '<span class="autlv aut-0">Lv.0</span>';
}elseif ($rbq<10 && $rbq>0) {
echo '<span class="autlv aut-1">Lv.1</span>';
}elseif ($rbq<20 && $rbq>=10) {
echo '<span class="autlv aut-2">Lv.2</span>';
}elseif ($rbq<40 && $rbq>=20) {
echo '<span class="autlv aut-3">Lv.3</span>';
}elseif ($rbq<80 && $rbq>=40) {
echo '<span class="autlv aut-4">Lv.4</span>';
}elseif ($rbq<100 && $rbq>=80) {
echo '<span class="autlv aut-5">Lv.5</span>';
}elseif ($rbq>=100) {
echo '<span class="autlv aut-6">Lv.6</span>';
}
}
/**输出作者文章总数,可以指定*/
function allpostnum($id){
$db = Typecho_Db::get();
$postnum=$db->fetchRow($db->select(array('COUNT(authorId)'=>'allpostnum'))->from ('table.contents')->where ('table.contents.authorId=?',$id)->where('table.contents.type=?', 'post'));
$postnum = $postnum['allpostnum'];
if($postnum=='0')
{
return '暂无文章';
}
else{
return '文章 '.$postnum.' 篇';
}
}
4. 最后就是添加样式了
scss样式如下,需要css 的可以自己转一下
.autlv {
font-size: 10px;
color: #fff;
display: inline-block;
vertical-align: text-top;
font-weight: normal;
border-radius: 2px;
line-height: 1.4;
padding: 0 4px;
margin-left: 5px;
letter-spacing: 0px;
}
.aut-0 {
background: #d1d5dc;
}
.aut-1 {
background: #448EF6;
}
.aut-2 {
background: #f6b044;
}
.aut-3 {
background: #c444f6;
}
.aut-4 {
background: #f69644;
}
.aut-5 {
background-image: -webkit-linear-gradient(0deg, #3ca5f6 0%, #a86af9 100%);
}
.aut-6 {
background: #f64444;
}
.aside-hunter-authors{
background: var(--background);
.vs {
border-radius: 100%;
}
ul{
padding: 14px;
list-style: none;
line-height: 2.5;
}
.item{
border-bottom: 1px dashed #eee;
margin-bottom: 0px;
position: relative;
padding-bottom: 4px;
.hunter-avatar{
float: left;
line-height: 55px;
.vatar{
position: relative;
img{
width: 45px;
border-radius: 100%;
}
.va_v_honor{
position: absolute;
bottom: 3px;
right: 0px;
width: 18px;
height: 18px;
}
}
}
.item-main{
min-height: 60px;
margin-left: 60px;
color: #393939;
h4{
font-size: 12px;
line-height: 1;
margin-bottom: 7px;
font-weight: normal;
color: #999;
i{
font-style: normal;
color: #aaa;
margin: 0 5px;
}
}
}
}
}
转载于:即刻学术
评论