10.文章首页置顶功能
Hexo Fluid 主题文章置顶功能
Hexo Fluid 主题支持文章置顶功能。通过在文章的 front-matter 中添加 pinned: true 字段,可以让该文章在首页或分类页优先显示。
如何配置
-
在文章 front-matter 中添加 pinned 字段
以 Markdown 文件为例:
1
2
3
4
5
6
7
8---
title: 置顶示例文章
pinned: true
tags:
- Hexo
categories:
- 教程
---只需在 front-matter 区块中添加
pinned: true即可。 -
主题配置检查
打开
themes/fluid/_config.yml,确认如下配置(一般默认已开启):1
2
3
4index:
post_sticky:
enable: true
icon: "iconfont icon-top"该配置用于在首页文章标题前显示置顶图标。
-
修改index.ejs
如果你想自定义置顶图标的显示方式,可以在
themes/fluid/layout/index.ejs文件中找到如下代码片段:1
2
3
4
5
6
7
8<h2 class="index-header">
''' 添加代码到这一行 '''
<a href="<%= post_url %>" target="<%- theme.index.post_url_target %>">
<%= post.title %>
</a>
</h2>添加以下代码:
1
2
3<% if (post.pinned) { %>
<i class="index-pin iconfont icon-top" title="Pinned post"></i>
<% } %>
常见问题 | FAQ
- Q: 可以置顶多篇文章吗?
- A: 可以,所有设置了
pinned: true的文章都会置顶,排序按时间或其他排序字段。
- A: 可以,所有设置了
- Q: 如何自定义置顶图标?
- A: 修改主题配置
index.post_sticky.icon字段即可。
- A: 修改主题配置
- Q: 置顶功能无效怎么办?
- A: 检查 front-matter 是否正确添加
pinned: true,并确认主题配置已开启置顶功能。
- A: 检查 front-matter 是否正确添加
总结
- 只需在 front-matter 添加
pinned: true,即可实现文章置顶。 - 适合用于推荐、公告等重要内容。
- 配置简单,效果直观。
如有疑问欢迎留言交流!
“觉得不错的话,给点打赏吧 ୧(๑•̀⌄•́๑)૭”
微信支付
支付宝支付
10.文章首页置顶功能
http://neurowave.tech/2025/02/12/1-10-文章置顶功能/