侧边栏壁纸
博主头像
尘荞Joueur博主等级

行动起来,活在当下

  • 累计撰写 86 篇文章
  • 累计创建 42 个标签
  • 累计收到 163 条评论

目 录CONTENT

文章目录
VPS

halo博客展示总访问量、总点赞数

Administrator
2023-01-09 / 0 评论 / 5 点赞 / 191 阅读 / 1950 字

核心代码

halo其实已经提供了接口查询总访问量、总点赞等信息,我目前在用的joe2.0主题的代码里面也写了获取总访问量并展示的代码,不过不知道什么原因现在注释掉了,估计是因为改用了卜算子统计吧!

/* 总访问量 */
initUV() {
	if (!ThemeConfig.enable_birthday) return;
	Utils.request({
		url: "/api/content/statistics/user",
	}).then((res) => {
		res && $("#site-uv").text(res.visitCount || 0);$("#total-like").text(res.likeCount || 0);
	});
}

调一下查询统计数据的接口,然后把数字展示到对应的地方。

joe2.0主题改造方法

  1. 打开登陆博客后台,找到 外观 - 主题编辑 模块
  2. 找到template/common/footer.ftl文件,搜索 <div class="site_life">
  3. 搜索到之后,在<div class="site_life">标签的下一行最前面加上以下代码,点击保存。
<i class="joe-font joe-icon-tongji"></i>总访问量&nbsp;<strong style="font-weight:500;color: var(--theme);" id="site-uv">0</strong>&nbsp;|&nbsp;<i class="joe-font joe-icon-dianzan"></i>总点赞&nbsp;<strong style="font-weight:500;color: var(--theme);" id="total-like">0</strong>&nbsp;|&nbsp;
  1. 找到source/js/min/common.min.js文件,搜索 initBirthday:function()
  2. initBirthday:function()前面加上以下代码,点击保存。
initUV:function(){if (!ThemeConfig.enable_birthday) return;Utils.request({url:"/api/content/statistics/user"}).then(t=>{t&&$("#site-uv").text(t.visitCount||0);$("#total-like").text(t.likeCount || 0);})},

image-1663216360734

5

评论区