帝国cms技巧之如何实现文章按月、周、日点击量

670 ℃

帝国cms技巧之如何实现文章按月、周、日点击量排序?在模型管理增加相应3个字段,分别是:DayHits WeekHits MonthHits 这3个字段全部在主表,int类型字段

再增加 ConditionHits 字段,为文本型,同样在主表 注意大小写

$time = mktime(0, 0, 0, 8, 5, 2010); //设置日期为2010年8月5号
$wzid = 35; //文章ID35
$Week = date("w", $time); //今天星期几
$Number = date("j", $time); //今天几号
$Month = date("m", $time); //今天是几月
$Years = date("Y", $time); //今天那年
$d = cal_days_in_month(CAL_GREGORIAN, $Month, $Years); //去得本月总天数
$Week_r = $Number – $Week; //本周日是几号
if ($Week_r < 1) {
    $Week_r = cal_days_in_month(CAL_GREGORIAN, $Month – 1, $Years) + $Week_r;
}
$Week_l = $Number + 7 – $Week – 1; //本周六是几号
if ($Week_l > $d) {
    $Week_l = $Week_l – $d;
}
$newsrs = $empire – >fetch1("select ConditionHits from {$dbtbpre}ecms_news where `id`={$wzid}");
$DayHitstime_k = mktime(0, 0, 0, date("m", $time), $Number, date("Y", $time));
$DayHitstime_j = $DayHitstime_k + 86400;
if (empty($newsrs['ConditionHits'])) { //判断月、周、日点击条件是否为空,如果为空,初始值
    $empire – >query("UPDATE `{$dbtbpre}ecms_news` SET `ConditionHits`='".$Number."|".$Week_r."-".$Week_l."|".$Month."',`DayHits`=1,`WeekHits`=1,`MonthHits`=1 WHERE `id`={$wzid}");
} else {
    $Daytj = explode("|", $newsrs['ConditionHits']);
    print_r($Daytj);
    if ($newsrs['ConditionHits'] != "".$Number."|".$Week_r."-".$Week_l."|".$Month."") {
        if ((int) $Daytj[0] != $Number) {
            $empire – >query("UPDATE `{$dbtbpre}ecms_news` SET `ConditionHits`='".$Number."|".$Daytj[1]."|".$Daytj[2]."',`DayHits`=0 WHERE `id`={$wzid}");
        }
        if ($Daytj[1] != "".$Week_r."-".$Week_l."") {
            $empire – >query("UPDATE `{$dbtbpre}ecms_news` SET `ConditionHits`='".$Daytj[0]."|".$Week_r."-".$Week_l."|".$Daytj[2]."',`WeekHits`=0 WHERE `id`={$wzid}");
        }
        if ((int) $Daytj[2] != (int) $Month) {
            $empire – >query("UPDATE `{$dbtbpre}ecms_news` SET `ConditionHits`='".$Daytj[0]."|".$Daytj[1]."|".$Month."',`MonthHits`=0 WHERE `id`={$wzid}");
        }
    } else {
        if ((int) $Daytj[0] == $Number) {
            $empire – >query("UPDATE `{$dbtbpre}ecms_news` SET `DayHits`=DayHits+1 WHERE `id`={$wzid}"); //今日点击+1
        }
        if ($Daytj[1] == $Week_r."-".$Week_l) {
            $empire – >query("UPDATE `{$dbtbpre}ecms_news` SET `WeekHits`=WeekHits+1 WHERE `id`={$wzid}"); //本周点击+1
        }
        if ((int) $Daytj[2] == (int) $Month) {
            $empire – >query("UPDATE `{$dbtbpre}ecms_news` SET `MonthHits`=MonthHits+1 WHERE `id`={$wzid}"); //本月点击+1
        }
    }
}

CMS网站被挂黑链应该如何解决?(如何防止黑链)

php如何把time()函数获取的当前时间转成指定格式

js关于Date对象的所有方法介绍

php如何利用函数修改时差

php哪些函数可以增加一天时间戳

标签: CMS网站, date, time, 主表, 字段

上面是“帝国cms技巧之如何实现文章按月、周、日点击量”的全面内容,想了解更多关于 帝国cms 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_1176.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

wordpress如何调用文章评论
事件绑定addEventListener和事件解除绑定removeEventListener的基本用法
帝国cms7.0, 7.2版本支付宝防掉单漏单异步处理插件
帝国CMS之整合PHPwind通行证接口教程
帝国cms如何用js控制当前栏目无限级高亮