phpcms模板标签没有调用全站最新发布的数据
所以参考phpcms本身自带的lists方法写了一个Countlists调用全站数据
/**
* 全站最热
* @param $data
*/
public function CountLists($data) {
$this->db->table_name = 'v9_news';
$catid = intval($data['catid']);
if(isset($data['where'])){
$sql = $data['where'];
}else{
$thumb = intval($data['thumb']) ? " AND thumb != ''" : '';
if(!empty($catid)) {
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 = "status=99 AND catid IN ($catids_str)".$thumb;
} else {
$sql = "status=99 AND catid='$catid'".$thumb;
}
}
else {
$sql = "status=99".$thumb;
}
}
$order = $data['order'];
$return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id');
//调用副表的数据
if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) {
$ids = array();
foreach ($return as $v) {
if (isset($v['id']) && !empty($v['id'])) {
$ids[] = $v['id'];
} else {
continue;
}
}
if (!empty($ids)) {
$this->db->table_name = $this->db->table_name.'_data';
$ids = implode('\',\'', $ids);
$r = $this->db->select("`id` IN ('$ids')", '*', '', '', '', 'id');
if (!empty($r)) {
foreach ($r as $k=>$v) {
if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]);
}
}
}
}
return $return;
}
因为指定了
$this->db->table_name = 'v9_news';
所以只有默认的文章模型可以用,其他模型暂时不行
调用方式为
{pc:content action="CountLists" num="5" order="id DESC"}
解决..