当前位置:网站首页>Rpcms method of obtaining articles under the specified classification
Rpcms method of obtaining articles under the specified classification
2022-07-07 17:07:00 【User 3402098】
I found a problem when doing the theme , It can't be said to be a problem , Just uncomfortable places .
Often the front page of the website is a display of articles of different categories in different modules , When making the homepage, I found that I didn't know how to get the articles under the specified classification .
Look at the rpcms Code of the default template , Discovery is the latest article 、 The hottest article encapsulates this functionality into a function , If you want to get the articles under the specified category, you need to change .
I found it on the Internet , notice rpcms There are sorted functions on the Forum , Just try it , Good , It also supports the acquisition of subcategories .
《 Sort out the common functions of templates 》 There are many other commonly used functions above , You can see if there is any demand .
function getLogsByCateId($id,$limit=10,$order=['a.upateTime'=>'desc']){
if(empty($id)) return array();
$LogsMod=new LogsMod();
$ids=[$id];
$category=Cache::read('category');
if(!empty($category[$id]['children'])){
$ids=array_merge($ids,$category[$id]['children']);
}
$logData=$LogsMod->cate($ids)->order($order)->limit($limit)->select();
return $logData['list'];
}Put this function in the template common.php In file , It can be called in the template , as follows :
{foreach getLogsByCateId(1) as $k=>$v}
<a href="{$v['url']}">{$v['title']}</a>
{/foreach}The first parameter is the classification to be obtained ID
The second parameter is the quantity obtained
The third parameter is sorting method
边栏推荐
- [Seaborn] implementation of combined charts and multi subgraphs
- ATM系统
- Flask搭建api服务-SQL配置文件
- DNS 系列(一):为什么更新了 DNS 记录不生效?
- 最新高频Android面试题目分享,带你一起探究Android事件分发机制
- 第九届 蓝桥杯 决赛 交换次数
- Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
- LeetCode刷题day49
- The latest interview experience of Android manufacturers in 2022, Android view+handler+binder
- 智慧物流平台:让海外仓更聪明
猜你喜欢

运算符

The process of creating custom controls in QT to encapsulating them into toolbars (II): encapsulating custom controls into toolbars

Seaborn data visualization

Master this promotion path and share interview materials

Temperature sensor chip used in temperature detector

谈谈 SAP 系统的权限管控和事务记录功能的实现

Talk about the realization of authority control and transaction record function of SAP system

Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching

Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images

Sator推出Web3游戏“Satorspace” ,并上线Huobi
随机推荐
Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls
Sator推出Web3遊戲“Satorspace” ,並上線Huobi
A tour of gRPC:03 - proto序列化/反序列化
The latest interview experience of Android manufacturers in 2022, Android view+handler+binder
谎牛计数(春季每日一题 53)
skimage学习(1)
电脑无法加域,ping域名显示为公网IP,这是什么问题?怎么解决?
Master this promotion path and share interview materials
LeetCode 1155. 掷骰子的N种方法 每日一题
LeetCode-SQL第一天
Sort out several important Android knowledge and advanced Android development interview questions
Sqlserver2014+: create indexes while creating tables
谈谈 SAP 系统的权限管控和事务记录功能的实现
Sator推出Web3游戏“Satorspace” ,并上线Huobi
浅谈 Apache Doris FE 处理查询 SQL 源码解析
Module VI
QT 图片背景色像素处理法
【Seaborn】组合图表:PairPlot和JointPlot
正在准备面试,分享面经
PLC:自动纠正数据集噪声,来洗洗数据集吧 | ICLR 2021 Spotlight