【phpcms v9】全站文章调用相关问题

1、首页、内页在不指定栏目时可以调用全站指定推荐位的文章。

2、首页、内页调用全站点击量最高的文章,需要修改文件。

默认情况下,phpcms只支持调用当前文章排行,代码如下: 

{pc:content action="hits" catid="$catid" num="10" order="views DESC" cache="3600"}
{loop $data $r}
  <li><a href="{$r[url]}">{$r[title]}</a></li>
{/loop}
{/pc}

 其中$catid为待调用栏目的id,如果想实现全站调用,需要修改phpcms\modules\content\classes\content_tag.class.php文件,找到以下函数,大约第148行: 

/** 
* 排行榜标签 
* @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; 
} 


直接替换成下面的代码即可(没有反应时更新缓存)

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(!empty($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"}

 

另一种调用方法:

{pc:content action="lists"  num="20" order="id DESC" cache="3600"}

https://blog.csdn.net/qq_35393869/article/details/83342105

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值