// 在页面加载前立即设置主题,避免闪烁 (function() { const theme = localStorage.theme || (window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"); if (theme === "dark" || (!localStorage.theme && window.matchMedia("(prefers-color-scheme: dark)").matches)) { document.documentElement.classList.add("dark"); } else { document.documentElement.classList.remove("dark"); } })(); '; $this->need('header.php'); // 计算最近6个月的日期范围 $endDate = new DateTime(); $startDate = new DateTime(); $startDate->modify('-5 months'); // 最近6个月(包含当前月) $startDate->modify('first day of this month'); // 从当月第一天开始 // 只显示最近6个月 $db = Typecho_Db::get(); // 查询所有已发布的文章,在PHP中进行日期筛选 $posts = $db->fetchAll($db->select('title', 'created', 'slug', 'cid') ->from('table.contents') ->where('table.contents.type = ?', 'post') ->where('table.contents.status = ?', 'publish') ->order('table.contents.created', Typecho_Db::SORT_ASC)); // 组织热力图数据 $heatmapData = []; foreach ($posts as $post) { $postDate = date('Y-m-d', $post['created']); $postDateTime = new DateTime($postDate); // 只处理最近6个月的数据 if ($postDateTime >= $startDate && $postDateTime <= $endDate) { if (!isset($heatmapData[$postDate])) { $heatmapData[$postDate] = [ 'count' => 0, 'articles' => [] ]; } $heatmapData[$postDate]['count']++; // 构建正确的文章链接(添加.html后缀) $postUrl = Typecho_Common::url($post['slug'] . '.html', $this->options->index); $heatmapData[$postDate]['articles'][] = [ 'title' => $post['title'], 'url' => $postUrl ]; } } // 补全最近6个月中所有日期的数据 $currentDate = clone $startDate; $endOfRange = clone $endDate; $endOfRange->modify('last day of this month'); for ($date = clone $currentDate; $date <= $endOfRange; $date->modify('+1 day')) { $dateString = $date->format('Y-m-d'); if (!isset($heatmapData[$dateString])) { $heatmapData[$dateString] = [ 'count' => 0, 'articles' => [] ]; } } // 计算月份标签的准确位置 $monthPositions = []; $tempDate = clone $startDate; $firstDayOfWeek = $tempDate->format('N'); // 1=周一, 7=周日 $offset = $firstDayOfWeek - 1; // 转换为0=周一, 6=周日 $currentMonth = (int)$tempDate->format('n'); $monthPositions[$currentMonth] = 0; // 第一个月从位置0开始 $dayCount = 0; while ($tempDate <= $endOfRange) { $month = (int)$tempDate->format('n'); if ($month != $currentMonth) { $monthPositions[$month] = $dayCount; $currentMonth = $month; } $dayCount++; $tempDate->modify('+1 day'); } // 生成最近6个月的月份标签和位置 $monthLabels = []; $currentMonth = clone $startDate; for ($i = 0; $i < 6; $i++) { $monthNum = (int)$currentMonth->format('n'); $position = isset($monthPositions[$monthNum]) ? $monthPositions[$monthNum] : 0; $monthLabels[] = [ 'name' => $currentMonth->format('n月'), 'position' => $position ]; $currentMonth->modify('+1 month'); } // 计算总周数 $totalDays = $endOfRange->diff($startDate)->days + 1; $totalWeeks = ceil(($totalDays + $offset) / 7); //以下为往年今日文章调用代码 // 获取当前日期信息 $current_month = date('m'); $current_day = date('d'); $current_year = date('Y'); // 查询往年今日文章 $db = Typecho_Db::get(); $select = $db->select() ->from('table.contents') ->where('type = ?', 'post') ->where('status = ?', 'publish'); // 获取所有文章然后手动过滤 $all_posts = $db->fetchAll($select); $past_posts = array(); foreach ($all_posts as $post) { $post_month = date('m', $post['created']); $post_day = date('d', $post['created']); $post_year = date('Y', $post['created']); // 筛选条件:同月同日,但不是今年 if ($post_month == $current_month && $post_day == $current_day && $post_year != $current_year) { $past_posts[] = $post; } } // 按创建时间倒序排列 usort($past_posts, function($a, $b) { return $b['created'] - $a['created']; }); ?> need("header.php"); ?> need('assets/lantern.html'); ?>
need("component/menu.php"); ?>
content); ?>
= 0 && $currentDayIndex < $totalDays): $tempDate->modify("+$currentDayIndex days"); $dateString = $tempDate->format('Y-m-d'); $dayData = isset($heatmapData[$dateString]) ? $heatmapData[$dateString] : ['count' => 0, 'articles' => []]; $count = $dayData['count']; // 确定颜色等级 $activityClass = 'activity-low'; if ($count === 1) $activityClass = 'activity-medium'; else if ($count === 2) $activityClass = 'activity-high'; else if ($count === 3) $activityClass = 'activity-higher'; else if ($count >= 4) $activityClass = 'activity-highest'; ?>
0): ?>
format('Y年m月d日'); ?> (篇)
widget('Widget_Contents_Post_Recent', 'pageSize=5')->to($posts); ?> next()): ?> created; $todayStart = strtotime('today'); $yesterdayStart = strtotime('yesterday'); if ($postTime >= $todayStart) { $timeText = '今天'; } elseif ($postTime >= $yesterdayStart) { $timeText = '昨天'; } else { $daysAgo = floor(($todayStart - $postTime) / (60 * 60 * 24)); if ($daysAgo < 7) { $timeText = $daysAgo . '天前'; } elseif ($daysAgo < 30) { $timeText = floor($daysAgo / 7) . '周前'; } else { $timeText = floor($daysAgo / 30) . '月前'; } } $postDate = date('Y-m-d', $postTime); // 获取文章分类信息 - 使用更可靠的方法 $categoryName = ''; $categoryUrl = ''; $showImages = false; // 方法1:直接通过posts对象获取分类 if ($posts->categories) { $categories = $posts->categories; if (!empty($categories)) { $category = current($categories); // 获取第一个分类 $categoryName = $category['name']; $categoryUrl = $category['permalink']; $showImages = in_array($categoryName, array('户外', '爸爸厨房', '探店')); } } // 方法2:如果方法1失败,使用备用方法 if (empty($categoryName)) { ob_start(); $posts->category(); $categoryOutput = ob_get_clean(); if (!empty($categoryOutput)) { $categoryName = strip_tags($categoryOutput); $showImages = in_array($categoryName, array('户外', '爸爸厨房', '探店')); // 尝试获取分类链接 $db = Typecho_Db::get(); $categoryRow = $db->fetchRow($db->select('mid') ->from('table.metas') ->where('name = ?', $categoryName) ->where('type = ?', 'category')); if ($categoryRow) { $categoryWidget = Typecho_Widget::widget('Widget_Metas_Category_List'); while ($categoryWidget->next()) { if ($categoryWidget->mid == $categoryRow['mid']) { $categoryUrl = $categoryWidget->permalink; break; } } } } } ?>

title(); ?>

fields->description; if (!empty($customDescription)) { // 如果有自定义描述,直接显示 echo Typecho_Common::subStr(strip_tags($customDescription), 0, 150, '...'); } else { // 如果没有自定义描述,按现有方式截取 if ($posts->excerpt) { echo Typecho_Common::subStr(strip_tags($posts->excerpt), 0, 150, '...'); } else { echo Typecho_Common::subStr(strip_tags($posts->content), 0, 150, '...'); } } ?>
content; preg_match_all('/]+src=["\']([^"\']+)["\'][^>]*>/i', $content, $matches); $images = $matches[1] ?? []; $displayImages = array_slice($images, 0, 4); ?>
文章图片
name; $adminMail = $user->mail; $comments = $db->fetchAll($db->select('author', 'text', 'created', 'parent', 'mail') ->from('table.comments') ->where('cid = ?', $posts->cid) ->where('status = ?', 'approved') ->where('author != ?', $adminName) ->where('mail != ?', $adminMail) ->where('parent = ?', 0) ->order('created', Typecho_Db::SORT_DESC) ->limit(10)); $processedComments = array(); foreach ($comments as $comment) { $commentAuthor = htmlspecialchars($comment['author']); $commentText = Typecho_Common::subStr(strip_tags($comment['text']), 0, 80, '...'); $processedComments[] = array( 'author' => $commentAuthor, 'text' => $commentText ); } ?>

暂无往年今日的文章,今天是个开始新篇章的好日子!

need("footer.php"); ?>