建站软件 优化软件 编程软件 网页辅助 站群程序 网站程序 图像处理 资源教程 字体下载 推荐软件


您的位置:首页 > 建站必知 > Phpcms怎么调用全站文章排行

Phpcms怎么调用全站文章排行

时间:2015-07-03 09:29:48  来源:免费模板网 作者:风雪 阅读次数 tagsphpcms

想在自己网站里面添加一个新的模块,调用整站的文章排行。这个功能怎么实现呢,请看下文
默认情况下,Phpcms只支持调用当前文章排行,代码如下: 

{pc:content action="hits" catid="$catid" num="10" order="views DESC" cache="3600"} 
其中$catid为待调用栏目的id,如果想实现全站调用,需要修改phpcms\modules\content\classes\content_tag.class.php文件,找到以下函数: 

 
代码如下:

/** 
* 排行榜标签 
* @param $data 
*/ 
public function hits($data) { 
$catid = intval($data['catid']); 
if(!$this->set_modelid($catid)) return false; 
$this->hits_db = pc_base::load_model('hits_model'); 
$sql = $desc = $ids = ''; 
$array = $ids_array = array(); 
$order = $data['order']; 
$hitsid = 'c-'.$this->modelid.'-%'; 
$sql = "hitsid LIKE '$hitsid'"; 
if(isset($data['day'])) { 
$updatetime = SYS_TIME-intval($data['day'])*86400; 
$sql .= " AND updatetime>'$updatetime'"; 

if($this->category[$catid]['child']) { 
$catids_str = $this->category[$catid]['arrchildid']; 
$pos = strpos($catids_str,',')+1; 
$catids_str = substr($catids_str, $pos); 
$sql .= " AND catid IN ($catids_str)"; 
} else { 
$sql .= " AND catid='$catid'"; 

$hits = array(); 
$result = $this->hits_db->select($sql, '*', $data['limit'], $order); 
foreach ($result as $r) { 
$pos = strpos($r['hitsid'],'-',2) + 1; 
$ids_array[] = $id = substr($r['hitsid'],$pos); 
$hits[$id] = $r; 

$ids = implode(',', $ids_array); 
if($ids) { 
$sql = "status=99 AND id IN ($ids)"; 
} else { 
$sql = ''; 

$this->db->table_name = $this->tablename; 
$result = $this->db->select($sql, '*', $data['limit'],'','','id'); 
foreach ($ids_array as $id) { 
if($result[$id]['title']!='') { 
$array[$id] = $result[$id]; 
$array[$id] = array_merge($array[$id], $hits[$id]); 


return $array; 

  

本文地址:https://www.freemoban.com/jzbz/2015/0703/2265.html

猜你喜欢
栏目推荐
模板推荐

Copyright:www.freemoban.com 免费模板网 All Rights Reserved 网站备案:辽ICP备19014872号-2   辽公网安备 21010602000376号  辽公网安备:42900402000182号

免责声明:本站部分资源来自互联网收集,版权归原创者所有,如果侵犯了你的权益,我们会及时删除侵权内容,联系QQ:1615187561 谢谢合作!