大香伊蕉在人线国产大影视-大香伊蕉在人线国产最新75-大香伊人久久精品一区二区-大香伊人中文字幕精品-大香煮伊手机一区-大香煮伊在线74

歡迎您光臨深圳塔燈網絡科技有限公司!
電話圖標 余先生:13699882642

網站百科

為您解碼網站建設的點點滴滴

首頁  >   > 技術知識

Phpcms V9 調用全站文章排行的解決方案_PHPCms教程

發表日期:2019-12 文章編輯:小燈 瀏覽次數:4618

今天忙于修改網站界面,想在首頁添加瀏覽排行功能,卻發現Phpcms竟然不支持調用全站文章排行。下午仔細研究了Phpcms源碼,終于找到解決辦法。

默認情況下,Phpcms只支持調用當前文章排行,代碼如下:

{pc:content  action="hits" catid="$catid" num="10" order="views DESC" cache="3600"}

其中$catid為待調用欄目的id,如果想實現全站調用,需要修改phpcms\modules\content\classes\content_tag.class.php文件,找到以下函數:

 
  1.     /** 
  2.  * 排行榜標簽 
  3.  * @param $data 
  4.  */ 
  5. public function hits($data) { 
  6.     $catid = intval($data['catid']); 
  7.     if(!$this->set_modelid($catid)) return false; 
  8.   
  9.     $this->hits_db = pc_base::load_model('hits_model'); 
  10.     $sql = $desc = $ids = ''
  11.     $array = $ids_array = array(); 
  12.     $order = $data['order']; 
  13.     $hitsid = 'c-'.$this->modelid.'-%'
  14.     $sql = "hitsid LIKE '$hitsid'"
  15.     if(isset($data['day'])) { 
  16.         $updatetime = SYS_TIME-intval($data['day'])*86400; 
  17.         $sql .= " AND updatetime>'$updatetime'"
  18.     } 
  19.     if($this->category[$catid]['child']) { 
  20.         $catids_str = $this->category[$catid]['arrchildid']; 
  21.         $pos = strpos($catids_str,',')+1; 
  22.         $catids_str = substr($catids_str$pos); 
  23.         $sql .= " AND catid IN ($catids_str)"
  24.     } else { 
  25.         $sql .= " AND catid='$catid'"
  26.     } 
  27.     $hits = array(); 
  28.     $result = $this->hits_db->select($sql'*'$data['limit'], $order); 
  29.     foreach ($result as $r) { 
  30.         $pos = strpos($r['hitsid'],'-',2) + 1; 
  31.         $ids_array[] = $id = substr($r['hitsid'],$pos); 
  32.         $hits[$id] = $r
  33.     } 
  34.     $ids = implode(','$ids_array); 
  35.     if($ids) { 
  36.         $sql = "status=99 AND id IN ($ids)"
  37.     } else { 
  38.         $sql = ''
  39.     } 
  40.     $this->db->table_name = $this->tablename; 
  41.     $result = $this->db->select($sql'*'$data['limit'],'','','id'); 
  42.     foreach ($ids_array as $id) { 
  43.         if($result[$id]['title']!='') { 
  44.             $array[$id] = $result[$id]; 
  45.             $array[$id] = array_merge($array[$id], $hits[$id]); 
  46.         } 
  47.     } 
  48.     return $array

修改代碼(見注釋):

 
  1. /** 
  2.  * 排行榜標簽 
  3.  * @param $data 
  4.  */ 
  5. public function hits($data) { 
  6.     $catid = intval($data['catid']); 
  7.   
  8.     $this->hits_db = pc_base::load_model('hits_model'); 
  9.     $sql = $desc = $ids = ''
  10.     $array = $ids_array = array(); 
  11.     $order = $data['order']; 
  12.     $hitsid = 'c-'.$this->modelid.'-%'
  13.     $sql = "hitsid LIKE '$hitsid'"
  14.     if(isset($data['day'])) { 
  15.         $updatetime = SYS_TIME-intval($data['day'])*86400; 
  16.         $sql .= " AND updatetime>'$updatetime'"
  17.     } 
  18.     if(!emptyempty($catid) && $catid>0) { //添加判斷:id是否為空 
  19.         if(!$this->set_modelid($catid)) return false; 
  20.         if($this->category[$catid]['child']) { 
  21.             $catids_str = $this->category[$catid]['arrchildid']; 
  22.             $pos = strpos($catids_str,',')+1; 
  23.             $catids_str = substr($catids_str$pos); 
  24.             $sql .= " AND catid IN ($catids_str)"
  25.         } else { 
  26.             $sql .= " AND catid='$catid'"
  27.         } 
  28.     } 
  29.       
  30.     $hits = array(); 
  31.     $result = $this->hits_db->select($sql'*'$data['limit'], $order); 
  32.     foreach ($result as $r) { 
  33.         $pos = strpos($r['hitsid'],'-',2) + 1; 
  34.         $ids_array[] = $id = substr($r['hitsid'],$pos); 
  35.         $hits[$id] = $r
  36.     } 
  37.     $ids = implode(','$ids_array); 
  38.     if($ids) { 
  39.         $sql = "status=99 AND id IN ($ids)"
  40.     } else { 
  41.         $sql = ''
  42.     } 
  43.     $this->db->table_name = $this->tablename; 
  44.     $result = $this->db->select($sql'*'$data['limit'],'','','id'); 
  45.     foreach ($ids_array as $id) { 
  46.         if($result[$id]['title']!='') { 
  47.             $array[$id] = $result[$id]; 
  48.             $array[$id] = array_merge($array[$id], $hits[$id]); 
  49.         } 
  50.     } 
  51.     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  轉載請注明出處

 


本頁內容由塔燈網絡科技有限公司通過網絡收集編輯所得,所有資料僅供用戶參考了本站不擁有所有權,如您認為本網頁中由涉嫌抄襲的內容,請及時與我們聯系,并提供相關證據,工作人員會在5工作日內聯系您,一經查實,本站立刻刪除侵權內容。本文鏈接:http://www.ruihost.net.cn/28191.html
相關
最新網站建設案例
 八年  行業經驗

多一份參考,總有益處

聯系深圳網站公司塔燈網絡,免費獲得網站建設方案及報價

咨詢相關問題或預約面談,可以通過以下方式與我們聯系

業務熱線:余經理:13699882642

Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.    

主站蜘蛛池模板: 伊在人亚洲香蕉精品区麻豆 | 国产精品国产自线拍手机观看 | 亚洲精品免费在线 | 亚洲一区二区三区免费视频 | 亚洲精品国产第一区二区图片 | 爱爱视频在线免费观看 | 老子影院午夜伦手机不卡6080 | 久久最新免费视频 | 国产在线看不卡一区二区 | 国产亚洲午夜精品 | 亚洲欧美在线观看91偷拍 | 91视频美女| 欧美成人xx大片 | 天天摸天天操免费播放小视频 | 老年人一级特黄aa大片 | 奇米影视666 | 九九热欧美 | 精品国产一区二区三区免费 | 日韩亚洲在线 | 欧美日韩久久毛片 | 国内精品久久久久久久aa护士 | www性| 免费视频网站在线观看黄 | 99精品高清不卡在线观看 | 亚洲精品麻豆一区二区 | 亚洲国产精品久久久久婷婷软件 | 大ji吧快给我别停受不了视频 | 毛片一区二区三区 | 亚洲久久草 | 免费观看成人久久网免费观看 | 成人午夜性视频欧美成人 | 成 人 黄 色 大 片 | 青青青国产深夜福利视频 | 综合网在线观看 | 一级特黄aaa大片在 一级特黄aaa大片在线观看 | 奇米综合 | 天啪天天久久天天综合啪 | 国产99久久亚洲综合精品 | 国产日产欧美一区二区三区 | 国产精品91视频 | 第一国内永久免费福利视频 |