hexo 添加近期文章

hexo-next主题添加近期文章板块

1. 添加代码

找到 next/layout/_macro/sidebar.swig 中的 if theme.links 。下拉到他的 endif 。添加代码如下:

{% if theme.recent_posts %}
    <div class="links-of-blogroll motion-element {{ "links-of-blogroll-" + theme.recent_posts_layout  }}">
      <div class="links-of-blogroll-title">
        <!-- modify icon to fire by szw -->
        <i class="fa fa-history fa-{{ theme.recent_posts_icon | lower }}" aria-hidden="true"></i>
        {{ theme.recent_posts_title }}
      </div>
      <ul class="links-of-blogroll-list">
        {% set posts = site.posts.sort('-date') %}
        {% for post in posts.slice('0', '5') %}
          <li>
            <a href="{{ url_for(post.path) }}" title="{{ post.title }}" target="_blank">{{ post.title }}</a>
          </li>
        {% endfor %}
      </ul>
    </div>
{% endif %}

2. 修改主题配置文件

添加:

recent_posts_title: 近期文章
recent_posts_layout: block
recent_posts: true
发布了33 篇原创文章 · 获赞 49 · 访问量 4452

猜你喜欢

转载自blog.csdn.net/qq_41086511/article/details/103537476