phpcms如何调取最近更新的文章
phpcms如何调取最近更新的文章?
phpcms v9调用全站最新文章(最近更新所有内容)
第一步 修改 phpcmsmodulescontentclassescontent_tag.class.php在最后面的 } 上面添加public function newcontent($data){$num = intval($data['limit']) ? intval($data['limit']) : '20';// 设置排序switch($data['order']){case '1':$order = ' `id` ASC ';break;case '2':$order = ' `id` DESC ';break;case '3':$order = ' `inputtime` ASC ';break;case '4':$order = ' `inputtime` DESC ';break;case '5':$order = ' `updatetime` ASC ';break;case '6':$order = ' `updatetime` DESC ';break;default:$order = ' `id` DESC ';}if($data['catid']){$catids = explode(',', $data['catid']);foreach($catids as $catid){$catid = intval($catid);if(empty($catid))continue;$this->set_modelid($catid);$where = $this->category[$catid]['child'] ? ' `catid` IN ('.$this->category[$catid]['arrchildid'].')' : " `catid` = $catid";$datas = $this->db->select($where, '*', $num, $order);$data[$catid]['data'] = $datas;// 记录本次的文章数$data['num'][] = count($datas);$model_num++;}}else{$models = getcache('model', 'commons');foreach($models as $model){$this->db->set_model($model['modelid']);$datas = $this->db->select('', '*', $num, $order);$data[$model['modelid']]['data'] = $datas;// 记录本次的文章数$data['num'][] = count($datas);$model_num++;}}if($data){// 获取每个模型应该截取的条数$num = ceil($num/$model_num);// 循环条数记录用于找出条数不满足的数量然后进行平均$w_num = $w_num_t = '';foreach($data['num'] as $num_t){if($num_t < $num){$w_num += $num-$num_t;$w_num_t++;}}// 判断是否有不满足平均数的 如果有那么就增加平均值if($w_num_t){$num += ceil($w_num/($model_num-$w_num_t));}$datas = array();foreach($data as $r){$r_n = '';if(is_array($r['data']))foreach($r['data'] as $r_t){$datas[] = $r_t;if(++$r_n == $num)break;}}return $datas;}else{return false;}}第二步:模板调用
其实就和默认的文章列表调用差不多{pc:content action="newcontent" }参数说明:
catid: 可有可无加了就只调用指定栏目的信息多个栏目请使用英文半角的 ,间隔
order:排序 参数值:1-7具体的含义在代码里面很容易看明白 不祥述
num:调用数量不指定默认调用20条以上就是phpcms如何调取最近更新的文章的详细内容,更多请关注小潘博客其它相关文章!