帝国CMS中自定义列表按时间调用信息
2025-10-09
帝国 CMS 中,自定义列表按时间调用信息可以通过灵动标签结合时间条件实现,支持按发布时间、更新时间等多种时间维度排序和筛选。以下是具体方法和示例
php
php
php
一、按发布时间(newstime)调用
newstime
是帝国 CMS 默认的可修改发布时间字段,适合大多数按时间排序的场景。
1. 调用最新发布的信息(按时间倒序)
php
<!-- 调用最新发布的10条信息 -->
[e:loop={"SELECT id,title,newstime,titleurl FROM phome_ecms_news
WHERE checked=1
ORDER BY newstime DESC -- 按发布时间倒序(最新的在前)
LIMIT 10",10,24,0}]
<li>
<a href="<?=$bqr['titleurl']?>"><?=esub($bqr['title'],30)?></a>
<span><?=date('Y-m-d',$bqr['newstime'])?></span>
</li>
[/e:loop]
2. 调用指定时间范围内的信息
例如调用近 7 天发布的信息:php
<?php
// 计算7天前的时间戳
$sevenDaysAgo = time() - 7 * 24 * 3600;
?>
[e:loop={"SELECT id,title,newstime,titleurl FROM phome_ecms_news
WHERE newstime > <?=$sevenDaysAgo?> -- 发布时间在7天内
AND checked=1
ORDER BY newstime DESC
LIMIT 8",8,24,0}]
<div class="news-item">
<h3><?=$bqr['title']?></h3>
<p>发布:<?=date('Y-m-d H:i',$bqr['newstime'])?></p>
</div>
[/e:loop]
二、按实际发布时间(truetime)调用
truetime
是系统记录的真实发布时间(不可手动修改),适合需要严格按实际发布时间筛选的场景。php
<!-- 按实际发布时间调用最新5条信息 -->
[e:loop={"SELECT id,title,truetime,titleurl FROM phome_ecms_news
WHERE checked=1
ORDER BY truetime DESC -- 按实际发布时间倒序
LIMIT 5",5,24,0}]
<p>
<a href="<?=$bqr['titleurl']?>"><?=$bqr['title']?></a>
<em><?=date('Y-m-d',$bqr['truetime'])?></em>
</p>
[/e:loop]
三、按最后修改时间(lastdotime)调用
lastdotime
记录内容最后一次修改的时间,适合展示 “最近更新” 的内容。php
<!-- 调用最近更新的6条信息 -->
[e:loop={"SELECT id,title,lastdotime,titleurl FROM phome_ecms_news
WHERE checked=1
AND lastdotime > 0 -- 排除未修改过的内容
ORDER BY lastdotime DESC -- 按最后修改时间倒序
LIMIT 6",6,24,0}]
<div class="update-item">
<a href="<?=$bqr['titleurl']?>"><?=$bqr['title']?></a>
<span>最近更新:<?=date('Y-m-d',$bqr['lastdotime'])?></span>
</div>
[/e:loop]
四、按月 / 年归档调用
按月份或年份分组调用历史内容,适合归档页面。1. 调用指定月份的信息(例如 2025 年 10 月)
<?php
// 2025年10月1日0点时间戳
$monthStart = strtotime('2024-06-01 00:00:00');
// 2025年10月30日23点59分时间戳
$monthEnd = strtotime('2025-10-30 23:59:59');
?>
[e:loop={"SELECT id,title,newstime,titleurl FROM phome_ecms_news
WHERE newstime BETWEEN <?=$monthStart?> AND <?=$monthEnd?>
AND checked=1
ORDER BY newstime DESC",0,24,0}]
<li><?=date('m-d',$bqr['newstime'])?>:<a href="<?=$bqr['titleurl']?>"><?=$bqr['title']?></a></li>
[/e:loop]
2. 动态获取当前月份的信息
<?php
// 当前月份第一天
$currentMonthStart = strtotime(date('Y-m-01 00:00:00'));
// 当前月份最后一天
$currentMonthEnd = strtotime(date('Y-m-t 23:59:59'));
?>
<div class="month-archive">
<h3><?=date('Y年m月')?> 归档</h3>
<ul>
[e:loop={"SELECT id,title,newstime,titleurl FROM phome_ecms_news
WHERE newstime BETWEEN <?=$currentMonthStart?> AND <?=$currentMonthEnd?>
AND checked=1
ORDER BY newstime DESC",0,24,0}]
<li>
<span><?=date('m-d',$bqr['newstime'])?></span>
<a href="<?=$bqr['titleurl']?>"><?=esub($bqr['title'],25)?></a>
</li>
[/e:loop]
</ul>
</div>
声明:本文来自用户分享和网络收集,仅供学习与参考,测试请备份。