[教程] Typecho 24小时发布文章数量

查看: 388|回复: 0
crll 发表于 2023-2-25 21:03:03
在functions.php代码文件里面添加如下代码:

  1. function get_recent_posts_number($days = 1,$display = true)
  2. {
  3. $db = Typecho_Db::get();
  4. $today = time() + 3600 * 8;
  5. $daysago = $today - ($days * 24 * 60 * 60);
  6. $total_posts = $db->fetchObject($db->select(array('COUNT(cid)' => 'num'))
  7. ->from('table.contents')
  8. ->orWhere('created < ? AND created > ?', $today,$daysago)
  9. ->where('type = ? AND status = ? AND password IS NULL', 'post', 'publish'))->num;
  10. if($display) {
  11. echo $total_posts;
  12. } else {
  13. return $total_posts;
  14. }
  15. }
复制代码

模板调用代码:

  1. <?php get_recent_posts_number(12); ?>
复制代码

参数: 12是12天,改成1即是24小时内
博主论坛 bzlt.net
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于本站联系我们FAQ友情链接免责声明生存法则

Build with for "make" Copyright © 2020-2022. Powered by Discuz! GMT+8, 2024-5-18 23:01

快速回复 返回顶部 返回列表