排行榜 统计
  • 建站日期:2020/07/11
  • 文章总数:151 篇
  • 评论总数:184 条
  • 分类总数:5 个
  • 最后更新:1月17日

主题添加互动读者及读者等级

本文阅读 1 分钟
首页 typecho 正文

本文最后更新于2022年12月23日, 已超过481天没有更新。 如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!

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;
                        }
                    }
                }
            }
        }

转载于:即刻学术

本文经授权后发布,本文观点不代表立场
-- 展开阅读全文 --
最好的余生:有家回,有人等,有饭吃
« 上一篇 11-08
主题 添加author page
下一篇 » 01-04
V注册会员 L评论等级
R4 条回复
  1. 米娅 :
    2021-05-02     iPhone /    Safari

    主题好看,请问怎么获得::(咦)

    1. LaoyaoV :
      2021-05-02     Win 10 /    Chrome

      @米娅

      免费开源良心主题,去朋友圈第一友情链接。

      1. 米娅 :
        2021-05-02     iPhone /    Safari

        @Laoyao

        你的在他的基础上还加了修改吧::(真棒)

        1. LaoyaoV :
          2021-05-03     iPhone /    Safari

          @米娅

          稍微修改了一些

没有更多评论了