实现调用文章所属栏目及点击数,调用全站文章排行的解决方法

默认情况下,Phpcms只支持调用当前文章排行,代码如下:
{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 {
$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;
}

①打开phpcmsmodulescontentclassescontent_tag.class.php文件;
②搜索“列表页标签”,即lists标签函数,应该在文件的56行左右,把lists标签函数的整段调用代码修改如下:

  修改代码(见注释):

复制代码代码如下:
/**
* 列表页标签
* @param $data
*/
publicfunction lists($data) {
$catid = intval($data[‘catid’]);
if(!$this->set_modelid($catid)) return false;
if(isset($data[‘where’])) {
$sql = $data[‘where’];
} else {
$thumb = intval($data[‘thumb’]) ? ” AND thumb != ”” : ”;
if($this->category[$catid][‘child’]) {
$catids_str = $this->category[$catid][‘arrchildid’];
$pos = strpos($catids_str,’,’)+1;
$catids_str = substr($catids_str, $pos);
$sql = “status=99 AND catid IN ($catids_str)”.$thumb;
} else {
$sql = “status=99 AND catid=’$catid'”.$thumb;
}
}
$order = $data[‘order’];
$return = $this->db->select($sql, ‘*’, $data[‘limit’], $order,
”, ‘id’);
//二次开发=============================================
foreach($returnas &$r){
$h_md=pc_base::load_model(‘hits_model’);
$get_db=$h_md->get_one(array(‘hitsid’=>”c-“.$this->db->modelid.”-“.$r[id]));
$r[‘views’]=$get_db[views];
$c_md=pc_base::load_model(‘category_model’);
$c_data = $c_md->get_one(array(‘catid’=>$r[catid]));
$r[‘catname’]=$c_data[catname];
}
//原文无此段落
原因:列表获得浏览次数=============================================
/* 2013年4月
*使用方法
* {loop $data $r}
* {$r[catname]}-{$r[title]}-{$r[views]}
* {/loop}
*/
//调用副表的数据
if (isset($data[‘moreinfo’]) && intval($data[‘moreinfo’]) == 1) {
$ids = array();
foreach ($returnas$v) {
if (isset($v[‘id’]) && !emptyempty($v[‘id’])) {
$ids[] = $v[‘id’];
} else {
continue;
}
}
if (!emptyempty($ids)) {
$this->db->table_name = $this->db->table_name.’_data’;
$ids = implode(”,”, $ids);
$r = $this->db->select(“`id` IN (‘$ids’)”, ‘*’, ”, ”, ”,
‘id’);
if (!emptyempty($r)) {
foreach ($ras$k=>$v) {
if (isset($return[$k])) $return[$k] = array_merge($v,
$return[$k]);
}
}
}
}
return$return;
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注