实现每评论一次自动排第一功能(Typecho版)

实现每评论一次自动排第一功能(Typecho版)

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

下面是主要代码(插入到 functions.php 中):

function Autofirst(){
    $db = Typecho_Db::get();
    $query = $db->select()->from('table.comments')->where('authorId = ?','0')->order('coid',Typecho_Db::SORT_DESC)->limit(100);
    $result = $db->fetchAll($query);
    $arrUrl = array();
    $arrAuthor = array();
    foreach ($result as $value) {
        if($value["url"]!==null){
            array_push($arrUrl,$value["url"]);
            array_push($arrAuthor,$value["author"]);
        }
    }
    $su=array_filter(array_merge(array_unique($arrUrl)));
    $sa=array_filter(array_merge(array_unique($arrAuthor)));
    $num=0;
    for($i=0;$i<count(array_unique($su));$i++){
        if($su[$i]!=="" && $num<16){
            $num+=1;
            $db1 = Typecho_Db::get();
            $query1 = $db1->select()->from('table.comments')->where('url = ?',$su[$i])->order('coid',Typecho_Db::SORT_DESC)->limit(100);
            $result1 = $db1->fetchAll($query1);
            $arrAuthor1 = array();
            foreach ($result1 as $value) {
                    array_push($arrAuthor1,$value["author"]);
            }
            echo '<a href="'.$su[$i].'" rel="external nofollow" class="item col-lg-3 col-md-3 visible-lg visible-md" target="_blank"><i class="glyphicon glyphicon-leaf"></i> '.$arrAuthor1[0].'</a>';
        }
    }
}

调用代码和 css:

[hide]

<div class="row autofirst visible-lg visible-md">
<p>
<i class="glyphicon glyphicon-th"></i> 每评论一次就会自动排在本栏目第一位
</p>
    <?php Autofirst(100) ?>
</div>
<style>
.autofirst{
    margin:20px 20px 5px 20px;
    padding:10px;
    box-shadow: 0 1px 8px rgba(0,0,0,0.12), 0 1px 8px rgba(0,0,0,0.24);
    background-color:white;
    border-radius:3px;
}.item{
    padding:5px 0px;
}
</style>

[/hide]

2

评论

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