Phpcms V9 调用全站文章排行的解决方法
默认情况下,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(!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"}
您可能感兴趣的文章
- 01-10phpcms常见问题解答
- 01-10phpcms语法规则
- 01-10PHPCMS网站转移空间教程
- 01-10PHPCMS2008 SP4 心情排行指数不显示的解决办法
- 01-10phpcms频道首页调用所有一级栏目及二级栏目
- 01-10phpcms标签模板及专题模板的制作
- 01-10PHPCMS系统自带标签说明
- 01-10为PHPCMS 2008 编辑器增加常用中文字体方法
- 01-10PHPcms 2008 注册选择模型关闭后,注册不能自动登录的问题
- 01-10phpcms模仿QQ和MSN消息提示的效果
阅读排行
本栏相关
- 01-10phpcms常见问题解答
- 01-10phpcms语法规则
- 01-10PHPCMS2008 SP4 心情排行指数不显示的解
- 01-10PHPCMS网站转移空间教程
- 01-10PHPCMS系统自带标签说明
- 01-10phpcms标签模板及专题模板的制作
- 01-10phpcms频道首页调用所有一级栏目及二
- 01-10PHPcms 2008 注册选择模型关闭后,注册
- 01-10为PHPCMS 2008 编辑器增加常用中文字体
- 01-10phpcms模仿QQ和MSN消息提示的效果
随机阅读
- 08-05dedecms(织梦)副栏目数量限制代码修改
- 01-10C#中split用法实例总结
- 01-10使用C语言求解扑克牌的顺子及n个骰子
- 08-05DEDE织梦data目录下的sessions文件夹有什
- 01-10delphi制作wav文件的方法
- 01-11ajax实现页面的局部加载
- 01-11Mac OSX 打开原生自带读写NTFS功能(图文
- 01-10SublimeText编译C开发环境设置
- 08-05织梦dedecms什么时候用栏目交叉功能?
- 04-02jquery与jsp,用jquery