在phpcms\libs\classes\model.class.php增加以下程序:
* @param string $sql 查询条件
*/
final public function count_sql($sql) {
$this->query($sql);
$res = $this->db->fetch_next();
$this->db->free_result();
return $res['num'];
}
在phpcms\modules\content\classes\content_tag.class.php增加
/**
* 全站最新内容
*/
public function newcontent($data){
$page = $data['page'] ? intval($data['page']) : 1;
$pagesize = intval($data['limit']) ? intval($data['limit']) : '10';
$maxnum = $data['maxnum'] ? intval($data['maxnum']) : 100;
$setpages = $data['setpages'] ? intval($data['setpages']) : 10;
$models = getcache('model', 'commons');
$sql = 'select * from (';
$count_sql = 'select sum(tmpcount) as num from (';
$i = 1;
foreach($models as $m){
$sql .= '(select id,catid,typeid,title,style,thumb,keywords,description,url,inputtime from '.$this->db->db_tablepre.$m['tablename'].' where status=99 and catid in(22,7,8,9)) ';
if($i < count($models)) $sql .= 'union ';
//获取总数
$count_sql .= '(select count(*) as tmpcount from '.$this->db->db_tablepre.$m['tablename'].' where status=99 and catid in(22,7,8,9))';
if($i < count($models)) $count_sql .= 'union all ';
$i++;
}
$count_sql .=') as a';
$this->number = $this->db->count_sql($count_sql);
$this->number = $this->number > $maxnum ? $maxnum : $this->number;
$page = max(intval($page), 1);
$offset = $pagesize*($page-1);
$this->pages = pages($this->number, $page, $pagesize, $data['urlrule'], $array, $setpages);
$sql .= 'order by inputtime desc,id desc limit '.$maxnum.') as a limit '.$offset.', '.$pagesize;
$this->db->query($sql);
$res = $this->db->fetch_array();
return $res;
}
前台调用:
{pc:content action="newcontent" num="100" return="data"}
{loop $data $r}
这里是要显示的数据内容
{/loop}
{/pc}