当前位置:网站首页>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
边栏推荐
猜你喜欢
Sator推出Web3游戏“Satorspace” ,并上线Huobi
直接上干货,100%好评
Pisa-Proxy SQL 解析之 Lex & Yacc
《产品经理必读:五种经典的创新思维模型》的读后感
谈谈 SAP 系统的权限管控和事务记录功能的实现
Reflections on "product managers must read: five classic innovative thinking models"
QT中自定义控件的创建到封装到工具栏过程(二):自定义控件封装到工具栏
值得一看,面试考点与面试技巧
[medical segmentation] attention Unet
【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
随机推荐
SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
LeetCode 1981. 最小化目标值与所选元素的差 每日一题
99% 用户在 Power BI 云端报表常犯错误
Interface oriented programming
mysql使用笔记一
国内首创!Todesk将RTC技术融入远程桌面,画质更清晰操作更流畅
【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
NeRF:DeepFake的最终替代者?
LeetCode 1981. Minimize the difference between the target value and the selected element one question per day
QML初学
Ray and OBB intersection detection
最新Android高级面试题汇总,Android面试题及答案
掌握这个提升路径,面试资料分享
LeetCode 1626. 无矛盾的最佳球队 每日一题
Arduino 控制的双足机器人
[designmode] facade patterns
time标准库
dapp丨defi丨nft丨lp单双币流动性挖矿系统开发详细说明及源码
[designmode] proxy pattern
LeetCode-SQL第一天