博客簿

Typecho 24小时发布文章数量

时间:4年前   阅读:2317

Typecho 24小时发布文章数量


在functions.php代码文件里面添加如下代码:

function get_recent_posts_number($days = 1,$display = true)
{
        $db = Typecho_Db::get();
        $today = time() + 3600 * 8;
        $daysago = $today - ($days  24  60 * 60);
        $total_posts = $db->fetchObject($db->select(array('COUNT(cid)' => 'num'))
              ->from('table.contents')
              ->orWhere('created < ? AND created > ?', $today,$daysago)
              ->where('type = ? AND status = ? AND password IS NULL', 'post', 'publish'))->num;
        if($display) {
            echo $total_posts;
        } else {
            return $total_posts;
        }
}

模板调用代码:

<?php get_recent_posts_number(12); ?>

参数: 12是12天,改成1即是24小时内


上一篇:Typecho 调用分类缩略名以及不带链接分类名

下一篇:Typecho 列表前面数字排序循环

网友评论