帝国CMS中实现按小时统计文章发布数的方法
2024-12-28
以下是在帝国CMS中实现按小时统计文章发布数的方法:
按照小时显示更新数量
用sql调用
6小时:<?=$empire->gettotal(select count(*) as total from {$dbtbpre}ecms_表 where newstime>UNIX_TIMESTAMP()-6*3600)?>
12小时:<?=$empire->gettotal(select count(*) as total from {$dbtbpre}ecms_表 where newstime>UNIX_TIMESTAMP()-12*3600)?>
24小时:<?=$empire->gettotal(select count(*) as total from {$dbtbpre}ecms_表 where newstime>UNIX_TIMESTAMP()-24*3600)?>
一个星期:<?=$empire->gettotal(select count(*) as total from {$dbtbpre}ecms_表 where newstime>UNIX_TIMESTAMP()-86400*7)?>
一个月:<?=$empire->gettotal(select count(*) as total from {$dbtbpre}ecms_表 where newstime>UNIX_TIMESTAMP()-86400*30)?>
灵动标签调用
6小时:[e:loop={'select count(*) as total from [!db.pre!]ecms_表 where newstime>UNIX_TIMESTAMP()-6*3600',0,24,0}]<?=$bqr[total]?>[/e:loop]
12小时:[e:loop={'select count(*) as total from [!db.pre!]ecms_表 where newstime>UNIX_TIMESTAMP()-12*3600',0,24,0}]<?=$bqr[total]?>[/e:loop]
24小时:[e:loop={'select count(*) as total from [!db.pre!]ecms_表 where newstime>UNIX_TIMESTAMP()-24*3600',0,24,0}]<?=$bqr[total]?>[/e:loop]
一个星期:[e:loop={'select count(*) as total from [!db.pre!]ecms_表 where newstime>UNIX_TIMESTAMP()-86400*7',0,24,0}]<?=$bqr[total]?>[/e:loop]
一个月:[e:loop={'select count(*) as total from [!db.pre!]ecms_表 where newstime>UNIX_TIMESTAMP()-86400*30',0,24,0}]<?=$bqr[total]?>[/e:loop]
12*3600即12小时
86400*7即7天
----------------------------------------------------------------------------------
统计昨天发表的文章数量
<?php
$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
?>
[e:loop={select count(*) as total from [!db.pre!]ecms_news where newstime BETWEEN $beginYesterday and $endYesterday,1,24,0}]<?=$bqr[total]?>[/e:loop] 篇 </li>
----------------------------------------------------------------------------------
当前栏目本周更新:
<?=$empire->gettotal(select count(*) as total from {$dbtbpre}ecms_news where classid='$GLOBALS[navclassid]' and newstime >UNIX_TIMESTAMP()-86400*7)?>
注释:按栏目统计一周发布文章数 加 classid='栏目id'
按当前栏目一周发布文章数 加 classid='$GLOBALS[navclassid]'
//php获取今日开始时间戳和结束时间戳
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
//php获取昨日起始时间戳和结束时间戳 (即:前一天)
$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
//调取这两天(包括今天):(修改昨天)--date('d')-1:这两天 、date('d')-2:这三天、以此类推(注意:$beginYesterday、$endYesterday这两个未改动,还是沿用的昨天的名称)
$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endYesterday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
//调取前两天(修改昨天)--date('d')-2:前两天 、date('d')-3:前三天、以此类推(注意:$beginYesterday、$endYesterday这两个未改动,还是沿用的昨天的名称)
$beginYesterday=mktime(0,0,0,date('m'),date('d')-2,date('Y'));
$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
//php获取上周起始时间戳和结束时间戳
$beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
$endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
//php获取本周起始时间戳和结束时间戳
$beginThisweek=mktime(0,0 ,0,date(m),date(d)-date(w)+1,date(Y));
$endThisweek=mktime(23,59,59,date(m),date(d)-date(w)+7,date(Y));
//php获取上月起始时间戳和结束时间戳
$beginLastmonth=mktime(0,0,0,date(m)-1,1,date(Y))
$endLastmonth=mktime(23,59,59,date(m),0,date(Y))
//php获取本月起始时间戳和结束时间戳
$beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
$endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'))
按照小时显示更新数量
用sql调用
6小时:<?=$empire->gettotal(select count(*) as total from {$dbtbpre}ecms_表 where newstime>UNIX_TIMESTAMP()-6*3600)?>
12小时:<?=$empire->gettotal(select count(*) as total from {$dbtbpre}ecms_表 where newstime>UNIX_TIMESTAMP()-12*3600)?>
24小时:<?=$empire->gettotal(select count(*) as total from {$dbtbpre}ecms_表 where newstime>UNIX_TIMESTAMP()-24*3600)?>
一个星期:<?=$empire->gettotal(select count(*) as total from {$dbtbpre}ecms_表 where newstime>UNIX_TIMESTAMP()-86400*7)?>
一个月:<?=$empire->gettotal(select count(*) as total from {$dbtbpre}ecms_表 where newstime>UNIX_TIMESTAMP()-86400*30)?>
灵动标签调用
6小时:[e:loop={'select count(*) as total from [!db.pre!]ecms_表 where newstime>UNIX_TIMESTAMP()-6*3600',0,24,0}]<?=$bqr[total]?>[/e:loop]
12小时:[e:loop={'select count(*) as total from [!db.pre!]ecms_表 where newstime>UNIX_TIMESTAMP()-12*3600',0,24,0}]<?=$bqr[total]?>[/e:loop]
24小时:[e:loop={'select count(*) as total from [!db.pre!]ecms_表 where newstime>UNIX_TIMESTAMP()-24*3600',0,24,0}]<?=$bqr[total]?>[/e:loop]
一个星期:[e:loop={'select count(*) as total from [!db.pre!]ecms_表 where newstime>UNIX_TIMESTAMP()-86400*7',0,24,0}]<?=$bqr[total]?>[/e:loop]
一个月:[e:loop={'select count(*) as total from [!db.pre!]ecms_表 where newstime>UNIX_TIMESTAMP()-86400*30',0,24,0}]<?=$bqr[total]?>[/e:loop]
12*3600即12小时
86400*7即7天
----------------------------------------------------------------------------------
统计昨天发表的文章数量
<?php
$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
?>
[e:loop={select count(*) as total from [!db.pre!]ecms_news where newstime BETWEEN $beginYesterday and $endYesterday,1,24,0}]<?=$bqr[total]?>[/e:loop] 篇 </li>
----------------------------------------------------------------------------------
当前栏目本周更新:
<?=$empire->gettotal(select count(*) as total from {$dbtbpre}ecms_news where classid='$GLOBALS[navclassid]' and newstime >UNIX_TIMESTAMP()-86400*7)?>
注释:按栏目统计一周发布文章数 加 classid='栏目id'
按当前栏目一周发布文章数 加 classid='$GLOBALS[navclassid]'
//php获取今日开始时间戳和结束时间戳
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
//php获取昨日起始时间戳和结束时间戳 (即:前一天)
$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
//调取这两天(包括今天):(修改昨天)--date('d')-1:这两天 、date('d')-2:这三天、以此类推(注意:$beginYesterday、$endYesterday这两个未改动,还是沿用的昨天的名称)
$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endYesterday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
//调取前两天(修改昨天)--date('d')-2:前两天 、date('d')-3:前三天、以此类推(注意:$beginYesterday、$endYesterday这两个未改动,还是沿用的昨天的名称)
$beginYesterday=mktime(0,0,0,date('m'),date('d')-2,date('Y'));
$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
//php获取上周起始时间戳和结束时间戳
$beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
$endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
//php获取本周起始时间戳和结束时间戳
$beginThisweek=mktime(0,0 ,0,date(m),date(d)-date(w)+1,date(Y));
$endThisweek=mktime(23,59,59,date(m),date(d)-date(w)+7,date(Y));
//php获取上月起始时间戳和结束时间戳
$beginLastmonth=mktime(0,0,0,date(m)-1,1,date(Y))
$endLastmonth=mktime(23,59,59,date(m),0,date(Y))
//php获取本月起始时间戳和结束时间戳
$beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
$endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'))
声明:本文来自用户分享和网络收集,仅供学习与参考,测试请备份。