实现效果步骤如下:
①打开\phpcms\modules\content\classes\content_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;
}
上面的函数代码里已经标注了新添加标签的函数代码,即23行至38行;
③前端页面模板调用代码的方法(示例)已经在上述函数代码里标明,我再重新说一下:
{loop $data$r}
{$r[catname]}-{$r[title]}-{$r[views]}
{/loop}