發表日期:2019-12 文章編輯:小燈 瀏覽次數:4238
默認情況下,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 瀏覽次數:4928
日期:2019-12 瀏覽次數:4333
日期:2019-12 瀏覽次數:4088
日期:2019-12 瀏覽次數:4328
日期:2019-12 瀏覽次數:4470
日期:2019-12 瀏覽次數:4237
日期:2019-12 瀏覽次數:4506
日期:2019-12 瀏覽次數:4149
日期:2019-12 瀏覽次數:4673
日期:2019-12 瀏覽次數:4680
日期:2019-12 瀏覽次數:4438
日期:2019-12 瀏覽次數:4992
日期:2019-12 瀏覽次數:4423
日期:2019-12 瀏覽次數:4233
日期:2019-12 瀏覽次數:4317
日期:2019-12 瀏覽次數:4206
日期:2019-12 瀏覽次數:4476
日期:2019-12 瀏覽次數:4289
日期:2019-12 瀏覽次數:4328
日期:2019-12 瀏覽次數:5675
日期:2019-12 瀏覽次數:4771
日期:2019-12 瀏覽次數:4151
日期:2019-12 瀏覽次數:4178
日期:2019-12 瀏覽次數:4259
日期:2019-12 瀏覽次數:4989
日期:2019-12 瀏覽次數:4125
日期:2019-12 瀏覽次數:4064
日期:2019-12 瀏覽次數:4378
日期:2019-12 瀏覽次數:3978
日期:2019-12 瀏覽次數:4271
Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.