当前位置:网站首页>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
第二个参数是获取的数量
第三个参数是排序方式
边栏推荐
- LeetCode 1031. Maximum sum of two non overlapping subarrays
- OpenGL personal notes
- 【源码解读】| LiveListenerBus源码解读
- Sqlserver2014+: create indexes while creating tables
- 【Seaborn】组合图表:FacetGrid、JointGrid、PairGrid
- 模块六
- QT中自定义控件的创建到封装到工具栏过程(二):自定义控件封装到工具栏
- LeetCode 1155. N ways to roll dice one question per day
- Deep listening array deep listening watch
- Master this promotion path and share interview materials
猜你喜欢

Interface oriented programming

如何在博客中添加Aplayer音乐播放器

字节跳动高工面试,轻松入门flutter

Module VI

SlashData开发者工具榜首等你而定!!!

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

科普达人丨一文弄懂什么是云计算?
![[Seaborn] combination chart: facetgrid, jointgrid, pairgrid](/img/89/a7cf40fb3a7622cb78ea1b92ffd2fb.png)
[Seaborn] combination chart: facetgrid, jointgrid, pairgrid

Introduction and use of gateway

Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
随机推荐
电脑无法加域,ping域名显示为公网IP,这是什么问题?怎么解决?
LeetCode 1477. Find two subarrays with sum as the target value and no overlap
Advanced C language -- function pointer
LeetCode 1981. Minimize the difference between the target value and the selected element one question per day
服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
[Seaborn] combination chart: pairplot and jointplot
【黄啊码】为什么我建议您选择go,而不选择php?
LeetCode 1774. 最接近目标价格的甜点成本 每日一题
LeetCode 312. Poke balloon daily
The latest interview experience of Android manufacturers in 2022, Android view+handler+binder
偶然升职的内心独白
深度监听 数组深度监听 watch
Proxmox VE重装后,如何无损挂载原有的数据盘?
LeetCode 120. 三角形最小路径和 每日一题
Arduino 控制的双足机器人
Binary search tree (features)
【Seaborn】组合图表:FacetGrid、JointGrid、PairGrid
整理几个重要的Android知识,高级Android开发面试题
ATM system
Direct dry goods, 100% praise