发表日期:2019-12 文章编辑:小灯 浏览次数:4000
默认情况下,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;
- }
修改代码(见注释):
- /**
- * 排行榜标签
- * @param $data
- */
- public function hits($data) {
- $catid = intval($data['catid']);
- $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(!emptyempty($catid) && $catid>0) { //添加判断:id是否为空
- if(!$this->set_modelid($catid)) return false;
- 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;
- }
修改代码后,无论设置栏目id为0或空,都能调取全站文章排行。
调用方法1:
{pc:content action="hits" catid="0" num="10" order="views DESC" cache="3600"}
调用方法2:
{pc:content action="hits" num="10" order="views DESC" cache="3600"}
作者:Esion 来源:http://www.cnblogs.com/esion 转载请注明出处
。
日期:2019-12 浏览次数:4667
日期:2019-12 浏览次数:4108
日期:2019-12 浏览次数:3847
日期:2019-12 浏览次数:4095
日期:2019-12 浏览次数:4216
日期:2019-12 浏览次数:3999
日期:2019-12 浏览次数:4265
日期:2019-12 浏览次数:3919
日期:2019-12 浏览次数:4434
日期:2019-12 浏览次数:4456
日期:2019-12 浏览次数:4201
日期:2019-12 浏览次数:4778
日期:2019-12 浏览次数:4163
日期:2019-12 浏览次数:3995
日期:2019-12 浏览次数:4052
日期:2019-12 浏览次数:3968
日期:2019-12 浏览次数:4239
日期:2019-12 浏览次数:4062
日期:2019-12 浏览次数:4061
日期:2019-12 浏览次数:5444
日期:2019-12 浏览次数:4533
日期:2019-12 浏览次数:3902
日期:2019-12 浏览次数:3951
日期:2019-12 浏览次数:4021
日期:2019-12 浏览次数:4745
日期:2019-12 浏览次数:3899
日期:2019-12 浏览次数:3821
日期:2019-12 浏览次数:4144
日期:2019-12 浏览次数:3766
日期:2019-12 浏览次数:4053
Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.