phpcmsHow to retrieve the recently updated articles?
phpcms v9 calls the latest articles of the entire site (all contents have been updated recently)
The first step is to modify phpcms\modules\content\classes content_tag.class.php Add
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; } }
to the last }. Step 2: Template call
In fact, it is almost the same as the default article list call
{pc:content action="newcontent" }
Parameter description:
catid: optional. If added, only the information of the specified column will be called. For multiple columns, please use English half-width, spaced
order: Sorting parameter value: 1-7 The specific meaning is easy to understand in the code.
num: Number of calls No Specify 20 calls by default
The above is the detailed content of How to retrieve recently updated articles in phpcms. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor