2025年度博文数据报告

2025年完美收官,2026年全新启封。

回顾一年的博客生活,想对他进行一个总结,进行一些数据统计,于是我求助于 DeepSeek 出个方案,它推荐了几款 WordPress 全年博文总结插件,如 Annual Archive、WP Annual Report 等,但都已好多年未更新了,wordpress.org 上也没有下载了,而推荐的 Simple Yearly Archive 是按年份归档插件,不适用。

于是 DeepSeek 给了个代码,通过在主题的 functions.php 文件中添加来实现此功能,并且可以在文章编辑器中直接插入短代码来完成,这样就能在一篇博文中回顾总结一年的博文数据了,具体效果如下:

有朋友问这个报告是如何实现 ,我将代码附后,有需要的网友自取:

// 生成2025年博文总结(含阅读量)
function munue_annual_summary_2025() {
$year = 2025; // 统计年份

// 获取所有文章
$args = array(
'year' => $year,
'posts_per_page' => -1,
'post_status' => 'publish',
'post_type' => 'post'
);

$posts = get_posts($args);
$total_posts = count($posts);

// 初始化统计数组
$monthly_stats = array_fill(1, 12, array('posts' => 0, 'views' => 0));
$categories_stats = array();
$all_views = 0;
$all_comments = 0;

// 遍历文章进行统计
foreach ($posts as $post) {
// 获取阅读量(使用不同的阅读量插件兼容方案)
$views = get_post_meta($post->ID, 'views', true); // WP-PostViews 插件
if (empty($views)) {
$views = get_post_meta($post->ID, '_post_views', true); // 其他插件
}
if (empty($views)) {
$views = get_post_meta($post->ID, 'post_views_count', true); // Jetpack
}
if (empty($views) || !is_numeric($views)) {
$views = 0;
}

// 获取评论数
$comments = get_comments_number($post->ID);

// 月度统计
$month = date('n', strtotime($post->post_date));
$monthly_stats[$month]['posts']++;
$monthly_stats[$month]['views'] += $views;

// 总统计
$all_views += $views;
$all_comments += $comments;

// 分类统计
$categories = wp_get_post_categories($post->ID);
foreach ($categories as $cat_id) {
$cat_name = get_cat_name($cat_id);
if (!isset($categories_stats[$cat_id])) {
$categories_stats[$cat_id] = array(
'name' => $cat_name,
'posts' => 0,
'views' => 0
);
}
$categories_stats[$cat_id]['posts']++;
$categories_stats[$cat_id]['views'] += $views;
}
}

// 热门文章(按阅读量排序)
$popular_args = array(
'year' => $year,
'posts_per_page' => 10,
'meta_key' => 'views',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'views',
'value' => '0',
'compare' => '>',
'type' => 'NUMERIC'
)
)
);
$popular_posts = get_posts($popular_args);

// 平均数据
$avg_views_per_post = $total_posts > 0 ? round($all_views / $total_posts) : 0;
$avg_comments_per_post = $total_posts > 0 ? round($all_comments / $total_posts, 1) : 0;

// 查找最高阅读量月份和文章
$max_views_month = 0;
$max_views_count = 0;
foreach ($monthly_stats as $month => $data) {
if ($data['views'] > $max_views_count) {
$max_views_count = $data['views'];
$max_views_month = $month;
}
}

// 生成HTML输出
ob_start();
?>
<div class="annual-summary-2025" style="
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 40px;
border-radius: 15px;
margin: 30px 0;
color: white;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
">
<div style="text-align: center; margin-bottom: 40px;">
<h1 style="color: white; margin-bottom: 10px; font-size: 2.5em;">📊 2025年度数据报告</h1>
<p style="opacity: 0.9;">Munue.com 年度内容运营总结</p>
</div>

<!-- 核心数据总览 -->
<div style="
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 40px;
">
<div style="
background: rgba(255,255,255,0.1);
padding: 25px;
border-radius: 10px;
text-align: center;
backdrop-filter: blur(10px);
">
<div style="font-size: 2.5em; font-weight: bold;"><?php echo $total_posts; ?></div>
<div style="opacity: 0.9;">发布文章</div>
</div>

<div style="
background: rgba(255,255,255,0.1);
padding: 25px;
border-radius: 10px;
text-align: center;
backdrop-filter: blur(10px);
">
<div style="font-size: 2.5em; font-weight: bold;"><?php echo number_format($all_views); ?></div>
<div style="opacity: 0.9;">总阅读量</div>
</div>

<div style="
background: rgba(255,255,255,0.1);
padding: 25px;
border-radius: 10px;
text-align: center;
backdrop-filter: blur(10px);
">
<div style="font-size: 2.5em; font-weight: bold;"><?php echo $avg_views_per_post; ?></div>
<div style="opacity: 0.9;">篇均阅读</div>
</div>

<div style="
background: rgba(255,255,255,0.1);
padding: 25px;
border-radius: 10px;
text-align: center;
backdrop-filter: blur(10px);
">
<div style="font-size: 2.5em; font-weight: bold;"><?php echo $all_comments; ?></div>
<div style="opacity: 0.9;">评论总数</div>
</div>
</div>

<!-- 月度阅读量图表 -->
<div style="
background: rgba(255,255,255,0.1);
padding: 30px;
border-radius: 10px;
margin-bottom: 40px;
backdrop-filter: blur(10px);
">
<h3 style="color: white; margin-bottom: 20px;">📈 月度阅读量趋势</h3>
<div style="display: flex; align-items: flex-end; height: 200px; gap: 15px; overflow-x: auto;">
<?php
$max_month_views = max(array_column($monthly_stats, 'views'));
$month_names = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'];

foreach ($monthly_stats as $month => $data):
$height = $max_month_views > 0 ? ($data['views'] / $max_month_views) * 150 : 5;
$is_max = ($month == $max_views_month);
?>
<div style="flex: 1; min-width: 70px; text-align: center;">
<div style="
background: <?php echo $is_max ? '#ff6b6b' : 'rgba(255,255,255,0.3)'; ?>;
height: <?php echo $height; ?>px;
border-radius: 5px 5px 0 0;
margin-bottom: 10px;
position: relative;
">
<div style="
position: absolute;
top: -25px;
left: 0;
right: 0;
font-size: 12px;
font-weight: bold;
"><?php echo number_format($data['views']); ?></div>
</div>
<div style="font-size: 14px; margin-bottom: 5px;"><?php echo $month_names[$month-1]; ?></div>
<div style="font-size: 12px; opacity: 0.8;"><?php echo $data['posts']; ?>篇</div>
</div>
<?php endforeach; ?>
</div>
<?php if ($max_views_month > 0): ?>
<div style="text-align: center; margin-top: 15px; opacity: 0.9;">
最热月份:<?php echo $max_views_month; ?>月,阅读量 <?php echo number_format($max_views_count); ?>
</div>
<?php endif; ?>
</div>

<!-- 热门文章TOP 10 -->
<?php if (!empty($popular_posts)): ?>
<div style="
background: rgba(255,255,255,0.1);
padding: 30px;
border-radius: 10px;
margin-bottom: 40px;
backdrop-filter: blur(10px);
">
<h3 style="color: white; margin-bottom: 25px;">🔥 热门文章 TOP 10</h3>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px;">
<?php foreach ($popular_posts as $index => $post):
setup_postdata($post);
$post_views = get_post_meta($post->ID, 'views', true);
if (empty($post_views)) $post_views = 0;
$comments = get_comments_number($post->ID);
$categories = get_the_category($post->ID);
$category_name = !empty($categories) ? $categories[0]->name : '未分类';
?>
<div style="
background: rgba(255,255,255,0.05);
padding: 20px;
border-radius: 8px;
border-left: 4px solid <?php
echo $index < 3 ? '#ff6b6b' : ($index < 6 ? '#4ecdc4' : '#45b7d1');
?>;
">
<div style="display: flex; align-items: center; margin-bottom: 10px;">
<span style="
background: <?php
echo $index < 3 ? '#ff6b6b' : ($index < 6 ? '#4ecdc4' : '#45b7d1');
?>;
color: white;
width: 30px;
height: 30px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
margin-right: 10px;
"><?php echo $index + 1; ?></span>
<div>
<a href="<?php echo get_permalink($post->ID); ?>" style="
color: white;
text-decoration: none;
font-weight: bold;
font-size: 16px;
display: block;
"><?php echo get_the_title($post->ID); ?></a>
<span style="font-size: 12px; opacity: 0.8; margin-top: 5px; display: block;">
📁 <?php echo $category_name; ?>
</span>
</div>
</div>

<div style="display: flex; justify-content: space-between; margin-top: 15px; font-size: 13px;">
<span>👁️ <?php echo number_format($post_views); ?> 阅读</span>
<span>💬 <?php echo $comments; ?> 评论</span>
<span>📅 <?php echo get_the_date('m-d', $post->ID); ?></span>
</div>
</div>
<?php endforeach;
wp_reset_postdata(); ?>
</div>
</div>
<?php endif; ?>

<!-- 分类阅读量统计 -->
<?php if (!empty($categories_stats)): ?>
<div style="
background: rgba(255,255,255,0.1);
padding: 30px;
border-radius: 10px;
backdrop-filter: blur(10px);
">
<h3 style="color: white; margin-bottom: 25px;">🏷️ 分类阅读量分析</h3>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px;">
<?php
// 按阅读量排序
usort($categories_stats, function($a, $b) {
return $b['views'] - $a['views'];
});

foreach ($categories_stats as $cat):
$percentage = $all_views > 0 ? round(($cat['views'] / $all_views) * 100, 1) : 0;
?>
<div style="
background: rgba(255,255,255,0.05);
padding: 20px;
border-radius: 8px;
">
<div style="display: flex; justify-content: space-between; margin-bottom: 10px;">
<span style="font-weight: bold; font-size: 16px;"><?php echo $cat['name']; ?></span>
<span style="opacity: 0.9;"><?php echo $cat['posts']; ?>篇</span>
</div>

<div style="margin-bottom: 10px;">
<div style="display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px;">
<span>总阅读量</span>
<span><?php echo number_format($cat['views']); ?></span>
</div>
<div style="background: rgba(255,255,255,0.1); height: 8px; border-radius: 4px; overflow: hidden;">
<div style="
background: linear-gradient(90deg, #4ecdc4, #44a08d);
width: <?php echo min(100, $percentage * 2); ?>%;
height: 100%;
"></div>
</div>
</div>

<div style="font-size: 12px; opacity: 0.8; text-align: center;">
占比 <?php echo $percentage; ?>% • 篇均 <?php echo $cat['posts'] > 0 ? round($cat['views'] / $cat['posts']) : 0; ?> 阅读
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>

<!-- 页脚 -->
<div style="
text-align: center;
margin-top: 40px;
padding-top: 20px;
border-top: 1px solid rgba(255,255,255,0.2);
font-size: 14px;
opacity: 0.8;
">
<p>✨ 感谢每一位读者的陪伴与支持 ✨</p>
<p>数据统计时间:<?php echo date('Y年m月d日 H:i:s'); ?></p>
<p>© <?php echo $year; ?> Munue.com • 年度数据报告</p>
</div>
</div>

<!-- 添加CSS动画 -->
<style>
.annual-summary-2025 .stat-card {
transition: transform 0.3s ease;
}
.annual-summary-2025 .stat-card:hover {
transform: translateY(-5px);
}
@media (max-width: 768px) {
.annual-summary-2025 {
padding: 20px !important;
}
.annual-summary-2025 h1 {
font-size: 1.8em !important;
}
}
</style>
<?php

return ob_get_clean();
}
add_shortcode('annual_summary_2025', 'munue_annual_summary_2025');

// 添加额外的阅读量统计功能(如果使用WP-PostViews插件)
function enhance_views_tracking() {
// 如果安装了WP-PostViews插件,使用其功能
if (function_exists('the_views')) {
// 已经支持,无需额外处理
} else {
// 提供基本的阅读量跟踪
add_action('wp_head', 'track_post_views');
function track_post_views() {
if (is_single()) {
$post_id = get_the_ID();
$count_key = 'views';
$count = get_post_meta($post_id, $count_key, true);
if ($count == '') {
$count = 0;
delete_post_meta($post_id, $count_key);
add_post_meta($post_id, $count_key, '0');
} else {
$count++;
update_post_meta($post_id, $count_key, $count);
}
}
}
}
}
add_action('init', 'enhance_views_tracking');

使用方法

步骤 1:添加代码

  1. 登录 WordPress 后台

  2. 进入「外观」→「主题文件编辑器」

  3. 选择 functions.php

  4. 将上面的代码粘贴到文件底部

  5. 点击「更新文件」

步骤 2:在页面中使用

  1. 创建新页面或编辑现有页面

  2. 在内容中添加短代码:【annual_summary_2025】

  3. 发布页面

步骤3:在文章中使用

  1. 编辑文章

  2. 在内容任意位置(通常在开头或结尾)

  3. 切换到「文本」模式(不是可视化)

  4. 输入短代码:【annual_summary_2025】

  5. 更新文章

注:实际使用时,短代码的 【】 改成 [ ]。

📊 2025 年度内容报告

随风沐虐 年度数据分析

📝
0
发布文章
👁️
0
总阅读量
💬
0
评论总数
📈
0
篇均阅读

📅 月度数据明细

一月
文章:12篇
阅读:35,998
评论:55
一月
二月
文章:7篇
阅读:20,605
评论:26
二月
三月
文章:13篇
阅读:214,375
评论:32
三月
四月
文章:15篇
阅读:28,771
评论:20
四月
五月
文章:16篇
阅读:30,493
评论:21
五月
六月
文章:10篇
阅读:20,795
评论:6
六月
七月
文章:12篇
阅读:23,985
评论:26
七月
八月
文章:12篇
阅读:23,009
评论:28
八月
九月
文章:3篇
阅读:7,037
评论:12
九月
十月
文章:11篇
阅读:17,172
评论:54
十月
十一月
文章:6篇
阅读:5,265
评论:32
十一月
十二月
文章:15篇
阅读:9,905
评论:59
十二月

🏷️ 热门标签TOP 9

TOP 1

联合国

📝 16 篇文章 👁️ 11,473 阅读
篇均阅读:717
TOP 2

使用教程

📝 14 篇文章 👁️ 33,633 阅读
篇均阅读:2402
TOP 3

国际节日

📝 12 篇文章 👁️ 9,609 阅读
篇均阅读:801
TOP 4

人工智能

📝 10 篇文章 👁️ 15,423 阅读
篇均阅读:1542
TOP 5

中国节日

📝 9 篇文章 👁️ 9,300 阅读
篇均阅读:1033
TOP 6

关停服务

📝 8 篇文章 👁️ 18,844 阅读
篇均阅读:2356
TOP 7

社评

📝 8 篇文章 👁️ 14,380 阅读
篇均阅读:1798
TOP 8

Google

📝 7 篇文章 👁️ 198,444 阅读
篇均阅读:28349
TOP 9

WordPress

📝 7 篇文章 👁️ 15,459 阅读
篇均阅读:2208

🔥 热门文章TOP 10

1

最新可用 Google 镜像、Google 学术镜像站点(2025年12月更新)

我们收集分享最新可用的 Google 搜...
阅读全文
2

苹果速度

趁着618大促的风潮,还是给爱人下单了 ...
阅读全文
3

无偿献血荣誉证,就医时自动减免门诊诊查费

前两天因湿疹去县中医院就诊,图方便就直接...
阅读全文
4

招商银行收 Google AdSense 被扣5美元中转行费用

上次我还疑惑,收到的 Google Ad...
阅读全文
5

2025,一切从简

2025年元旦,如期而至,甚至有点猝不及...
阅读全文
6

卖了一个域名

433元,真是意外之财! 事情是这样的:...
阅读全文
7

Google Chrome 已不支持 RSS 阅读器 Feedbro 扩展程序

管理和阅读 RSS 我用的是 Googl...
阅读全文
8

WordPress 建议更新 PHP 版本,推荐 8.3 或更高版本

将网站 WordPress 程序更新到 ...
阅读全文
9

如何删除微信通讯录中”我的企业“联系人

腾讯推出企业微信后,微信中多出了个”我的...
阅读全文
10

WordPress 网站如何开启维护模式?

网站因更新或维护等原因,会导致访问出错的...
阅读全文

📂 分类数据统计

技术

38
文章数
281,314
阅读量
159
评论数
篇均阅读:7403 篇均评论:4.2

节日

34
文章数
27,979
阅读量
12
评论数
篇均阅读:823 篇均评论:0.4

资讯

25
文章数
45,908
阅读量
40
评论数
篇均阅读:1836 篇均评论:1.6

记录

14
文章数
32,979
阅读量
84
评论数
篇均阅读:2356 篇均评论:6

观点

9
文章数
21,306
阅读量
48
评论数
篇均阅读:2367 篇均评论:5.3

阅读

7
文章数
14,313
阅读量
18
评论数
篇均阅读:2045 篇均评论:2.6

拾遗

5
文章数
13,611
阅读量
10
评论数
篇均阅读:2722 篇均评论:2


历史上的今天:

相关推荐

百度统计将于2月29日下线事件分析等多个功能

百度统计是许多中小草根站长选择的网络统计服务,近日登录百度统计网站,提示将于2024年2月29日下线事件分析、 系统环境、 忠诚度等多个实用功能。为避免数据丢失,建议您尽快完成历史数据的下载备份。 重要通知 百度统计概况板块的「事件分析」、 「系统环境」、 「忠诚度」报告将于2024年2月29日下线,为避免数据丢失 ...

恭喜,您的百家号账号被解除封停

这是今天最开心的事了!16:36 收到短信:【百度】恭喜,您的百家号账号被解除封停。 经过漫长的七年之久的申诉,百度终于把我遭封禁的百家号账号“醒悟的凡灵”解除封停了。 翻看了下申诉记录,我最早是在2019年1月12日发起的申诉:百家号运营情况正常,没有发生违纪行为,请求解封,谢谢。但被判定申诉失败,原因是: ...

iOS 16.7.13 更新已经下载,安装时提示校验不通过怎么办?

前段时间,苹果公司突然针对老设备推出了 iOS 16.7.13 版本更新,我的 iPhone X 也收到了推送。更新说提供了重要的错误修复,所以我在马上进行下载安装。 但下载完成进行安装时,却提示“无法验证更新”,我多次重试都没成功。今天收到网友留言:已经下载了的更新还没有安装,提示校验不通过,要怎么删除呢?我原想着官 ...

Typecho 版本 1.3.0,大家升级了吗?

继 Typecho 发布 1.2.1 版本两年半后,突然在网站后台收到推送:官方最新版本是 1.3.0 。 我到官网查看此次正式稳定版的开发日志,竟然没找到,还停留在“安全更新:Typecho 1.2.1”,作者是不太喜欢码字的主,前一篇是“这不是玩笑,我们回来了:Typecho 1.2.0”,时间跨度五年多,以难为作者还能保持着更新。 Typecho ...

14 条评论

  1. 元旦快乐!
    报告页面很是精美,数据也很完整!
    2026,加油!

    • @Lvtu 觉得可以做成一个简单的插件,这样每年年终时都可直接输出报告。

      • @maqingxi 嗯,其实在报告页面加个时间判断也可以。。。

  2. ds挺强呀。技术类的阅读最多。

  3. 代码可以分享出来?我也行体验,园地快乐。

  4. wow,拿走多谢啦

    • @老何 你客气了。就是想加个留言排行榜,死活查询不出数据,最后只好放弃了。

  5. 厉害哇!我本想看看我的,结果发现没写啥东西。

回复 Lvtu 取消回复

您的电子邮件地址不会被公开,必填项已用*标注。