phpcms v9全站点击量排行代码

前台:

<ul>
{pc:content action=”sitehits” siteid=”1″ num=”10″ order=”views DESC” cache=”3600″}
{loop $data $r}
{if $n>3}
<li><span class=”nlspan”>{$n}</span><a href=”{$r[url]}” title=”{$r[title]}”>{str_cut($r[title],58,””)}</a></li>
{else}
<li><span>{$n}</span><a href=”{$r[url]}” title=”{$r[title]}”>{str_cut($r[title],58,””)}</a></li>
{/if}
{/loop}
{/pc}
</ul>

后台 phpcms/modules/content/classes/content_tag.class.php

/**
* sitehits站点点击排行
* @param $data
*/
function sitehits($data){
if(empty($data[‘siteid’])) return false;
$siteid = intval($data[‘siteid’]);
$this->hits_db = pc_base::load_model(‘hits_model’);
$category_content = getcache(‘category_content’,’commons’);
$catid = ”;
//获取站点下所有栏目ID

foreach($category_content as $key=>$val){
if($val==$siteid){
if($key!=11 && $key!=10){ //过滤不想统计的栏目
$catid .= $comma.$key;
$comma=’,’;
}
}
}
//获取点击排行

$r = $this->hits_db->select(‘catid in(‘.$catid.’)’,’hitsid’,$data[‘limit’],$data[‘order’]);
$return = array();
$sitemodel_model_db = pc_base::load_model(‘sitemodel_model’);
$this->db_config = pc_base::load_config(‘database’);
$tablepre = $this->db_config[‘default’][‘tablepre’];
foreach($r as $key){
preg_match_all(‘/-(\d+)-/’,$key[‘hitsid’],$modelid);
$id = substr($key[‘hitsid’],(strpos($key[‘hitsid’],’-‘,2)+1));
$tablename = $sitemodel_model_db->get_one(array(‘modelid’=>$modelid[1][0]),’tablename’);
$this->db->table_name = $tablepre.$tablename[‘tablename’];
$return[] = array_merge($return,$this->db->get_one(array(‘id’=>$id)));
}
return $return;
}

本文来自转载和修改

文章链接:,本站部分内容来自互联网,如不慎侵害的您的权益,请告知,我们将尽快删除!

发表评论