Hexo Next主題中,首頁文章默認排序方式是按照時間逆序來排的,越新的文章排在越前面。當我們想讓訪客一進來就能看到推薦的文章時,可以將這些文章置頂。
1 卸載原插件和安裝置頂插件
執行下面兩行命令:
npm uninstall hexo-generator-index --save
npm install hexo-generator-index-pin-top --save
在新增文章的開頭中加入top: true,比如:
---
title: Hexo Next主題設置文章置頂
id: a1
date: 2020-01-03 17:26:01
categories: Hexo
tags: Next主題
top: true
---
2 設置置頂標誌
打開**\themes\your theme\layout_macro\post.swig**
找到<div class=“post-meta”>下面插入一下代碼:
{% if post.top %}
<i class="fa fa-thumb-tack"></i>
<font color="RED">置頂</font>
<span class="post-meta-divider">|</span>
{% endif %}
至此,功能已完成。