10.文章首页置顶功能

Hexo Fluid 主题文章置顶功能

Hexo Fluid 主题支持文章置顶功能。通过在文章的 front-matter 中添加 pinned: true 字段,可以让该文章在首页或分类页优先显示。

如何配置

  1. 在文章 front-matter 中添加 pinned 字段

    以 Markdown 文件为例:

    1
    2
    3
    4
    5
    6
    7
    8
    ---
    title: 置顶示例文章
    pinned: true
    tags:
    - Hexo
    categories:
    - 教程
    ---

    只需在 front-matter 区块中添加 pinned: true 即可。

  2. 主题配置检查

    打开 themes/fluid/_config.yml,确认如下配置(一般默认已开启):

    1
    2
    3
    4
    index:
    post_sticky:
    enable: true
    icon: "iconfont icon-top"

    该配置用于在首页文章标题前显示置顶图标。

  3. 修改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 的文章都会置顶,排序按时间或其他排序字段。
  • Q: 如何自定义置顶图标?
    • A: 修改主题配置 index.post_sticky.icon 字段即可。
  • Q: 置顶功能无效怎么办?
    • A: 检查 front-matter 是否正确添加 pinned: true,并确认主题配置已开启置顶功能。

总结

  • 只需在 front-matter 添加 pinned: true,即可实现文章置顶。
  • 适合用于推荐、公告等重要内容。
  • 配置简单,效果直观。

如有疑问欢迎留言交流!


“觉得不错的话,给点打赏吧 ୧(๑•̀⌄•́๑)૭”

微信二维码

微信支付

支付宝二维码

支付宝支付

10.文章首页置顶功能
http://neurowave.tech/2025/02/12/1-10-文章置顶功能/
作者
Artin Tan
发布于
2025年2月12日
更新于
2025年7月7日