Phpcms v9调用全站文章排序榜实现方法
发布:smiling 来源: PHP粉丝网 添加日期:2015-03-24 14:12:41 浏览: 评论:0
Phpcms只支持调用当前文章排行,代码也是相当的简单,但是我想调用全站文章的排行这一点它做得不如 dedecms好.
v9调用当前栏目排行代码如下:
{pc:content action="hits" catid="$catid" num="10" order="views DESC" cache="3600"}
其中$catid为待调用栏目的id,如果想实现全站调用,需要修改phpcmsmodulescontentclassescontent_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 { //开源软件:phpfensi.com
- $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"}
Tags: Phpcms全站文章 Phpcms文章排序
- 上一篇:PHPCMS V9绑定多域名的方法
- 下一篇:Phpcms V9随机文章的调用方法
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)