下面是主要代码(插入到 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]
评论