当前位置:网站首页>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
边栏推荐
- [medical segmentation] attention Unet
- LocalStorage和SessionStorage
- Temperature sensor chip used in temperature detector
- 面向接口编程
- QT视频传输
- time标准库
- ByteDance Android gold, silver and four analysis, Android interview question app
- 掌握这套精编Android高级面试题解析,oppoAndroid面试题
- LeetCode 1477. Find two subarrays with sum as the target value and no overlap
- Test case management tool recommendation
猜你喜欢
《产品经理必读:五种经典的创新思维模型》的读后感
[designmode] proxy pattern
正在准备面试,分享面经
ByteDance Android gold, silver and four analysis, Android interview question app
MRS离线数据分析:通过Flink作业处理OBS数据
最新高频Android面试题目分享,带你一起探究Android事件分发机制
测试用例管理工具推荐
Temperature sensor chip used in temperature detector
整理几个重要的Android知识,高级Android开发面试题
QML beginner
随机推荐
Pychart ide Download
Pisa-Proxy SQL 解析之 Lex & Yacc
一文读懂数仓中的pg_stat
掌握这套精编Android高级面试题解析,oppoAndroid面试题
如何选择合适的自动化测试工具?
LeetCode 213. 打家劫舍 II 每日一题
浅浅理解.net core的路由
值得一看,面试考点与面试技巧
DNS 系列(一):为什么更新了 DNS 记录不生效?
Sator launched Web3 game "satorspace" and launched hoobi
【Seaborn】组合图表:FacetGrid、JointGrid、PairGrid
LeetCode 120. 三角形最小路径和 每日一题
Shallow understanding Net core routing
Reflections on "product managers must read: five classic innovative thinking models"
DAPP defi NFT LP single and dual currency liquidity mining system development details and source code
[PHP] PHP interface inheritance and interface multi inheritance principle and implementation method
LeetCode 1049. Weight of the last stone II daily question
面向接口编程
科普达人丨一文弄懂什么是云计算?
Advanced C language -- function pointer