当前位置:网站首页>rpcms获取指定分类下的文章的方法
rpcms获取指定分类下的文章的方法
2022-07-07 15:34:00 【用户3402098】
在做主题的时候发现了一个问题,也不能说是问题,就是不太舒服的地方。
往往网站首页是不同模块对不同分类的文章进行展示,在制作首页的时候发现不知道该如何获取指定分类下的文章。
查看了rpcms默认模板的代码,发现是把最新文章、最热文章这种功能性的单独封装成函数了,如果想获取指定分类下的文章就需要改改了。
在网上找了找,看到rpcms论坛上有整理好的函数,就用了下试试,挺好的,还支持子分类的获取。
《模板常用的功能函数整理》上面还有很多其他常用函数,可以看看有没有需求。
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'];
}把这个函数放到模板的common.php文件中,在模板就可以调用了,如下:
{foreach getLogsByCateId(1) as $k=>$v}
<a href="{$v['url']}">{$v['title']}</a>
{/foreach}第一个参数是需要获取的分类ID
第二个参数是获取的数量
第三个参数是排序方式
边栏推荐
- Inner monologue of accidental promotion
- 在哪个期货公司开期货户最安全?
- [Seaborn] combination chart: pairplot and jointplot
- 如何在博客中添加Aplayer音乐播放器
- SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
- [Seaborn] implementation of combined charts and multi subgraphs
- 最新2022年Android大厂面试经验,安卓View+Handler+Binder
- 谎牛计数(春季每日一题 53)
- 爬虫(17) - 面试(2) | 爬虫面试题库
- dapp丨defi丨nft丨lp单双币流动性挖矿系统开发详细说明及源码
猜你喜欢

科普达人丨一文弄懂什么是云计算?

最新阿里P7技术体系,妈妈再也不用担心我找工作了

Shallow understanding Net core routing

QT picture background color pixel processing method

应用在温度检测仪中的温度传感芯片
As an Android Developer programmer, Android advanced interview

水平垂直居中 方法 和兼容

Binary search tree (features)

两类更新丢失及解决办法

skimage学习(3)——使灰度滤镜适应 RGB 图像、免疫组化染色分离颜色、过滤区域最大值
随机推荐
第九届 蓝桥杯 决赛 交换次数
LeetCode 1626. 无矛盾的最佳球队 每日一题
[medical segmentation] attention Unet
LeetCode 403. Frog crossing the river daily
网关Gateway的介绍与使用
最新Android高级面试题汇总,Android面试题及答案
模块六
The process of creating custom controls in QT to encapsulating them into toolbars (II): encapsulating custom controls into toolbars
掌握这个提升路径,面试资料分享
LeetCode 120. 三角形最小路径和 每日一题
LeetCode 300. Daily question of the longest increasing subsequence
null == undefined
Sort out several important Android knowledge and advanced Android development interview questions
Number of exchanges in the 9th Blue Bridge Cup finals
Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls
如何在软件研发阶段落地安全实践
LeetCode 1774. The dessert cost closest to the target price is one question per day
Master this promotion path and share interview materials
LocalStorage和SessionStorage
LeetCode 1696. Jumping game VI daily question