想在首頁(yè)添加瀏覽排行功能,卻發(fā)現(xiàn)Phpcms竟然不支持調(diào)用全站文章排行。仔細(xì)研究了Phpcms源碼,終于找到解決辦法。
成都創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供宜陽(yáng)網(wǎng)站建設(shè)、宜陽(yáng)做網(wǎng)站、宜陽(yáng)網(wǎng)站設(shè)計(jì)、宜陽(yáng)網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、宜陽(yáng)企業(yè)網(wǎng)站模板建站服務(wù),10余年宜陽(yáng)做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
默認(rèn)情況下,Phpcms只支持調(diào)用當(dāng)前文章排行,代碼如下:
{pc:content action="hits" catid="$catid" num="10" order="views DESC" cache="3600"}
其中$catid為待調(diào)用欄目的id,如果想實(shí)現(xiàn)全站調(diào)用,需要修改phpcms\modules\content\classes\content_tag.class.php文件,找到以下函數(shù):
/**
* 排行榜標(biāo)簽
* @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;
}
修改代碼(見(jiàn)注釋):
/**
* 排行榜標(biāo)簽
* @param $data
*/
public function hits($data) {
$catid = intval($data['catid']);
if(!empty($catid) && $catid>0) { //添加判斷:id是否為空
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(!emptyempty($catid) && $catid>0) { //添加判斷:id是否為空
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;
}
修改代碼后,無(wú)論設(shè)置欄目id為0或空,都能調(diào)取全站文章排行。
調(diào)用方法1:
{pc:content action="hits" catid="0" num="10" order="views DESC" cache="3600"}
調(diào)用方法2:
{pc:content action="hits" num="10" order="views DESC" cache="3600"}
網(wǎng)站題目:phpcmsV9如何調(diào)用全站文章排行
本文地址:http://vcdvsql.cn/article30/pehhpo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、、網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、網(wǎng)站收錄、網(wǎng)站維護(hù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)