按年份获取Jekyll帖子 [英] Get Jekyll Posts by Year

查看:81
本文介绍了按年份获取Jekyll帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您愿意我的网站上的所有帖子,我都在存档".我想收集一年中的所有帖子.这段代码可以正常工作.我希望它在需要时生成<h2>2014</h2>.

I'm making an "archive" if you will of all the posts on my site. I want to gather all the posts from a year. This code works fine, however; I want it to generate the <h2>2014</h2> when needed.

基本上,如果年份为2014,则渲染 <h2>2014</h2> ,并根据给定的所有帖子(带有日记类别)制作一个 <ul> 年.

如果有人知道任何按年份存档的.rb插件,请告诉我!

If anyone knows of any .rb plugins that archive by year, let me know!

<h2>2014</h2>
{% for post in site.categories.journal %}
    {% capture year %}{{post.date | date: "%Y"}}{% endcapture %}
        {% if year == "2014" %}
                <ul class="posts-in-year">
                    <li><p><a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a> &mdash; {{ post.date | date: "%B %d" }}</p></li>
                </ul>
        {% endif %}
{% endfor %}

推荐答案

<h2>2014</h2>
    <ul class="posts-in-year">
    {% for post in site.categories.journal %}
     {% capture year %}{{post.date | date: "%Y"}}{% endcapture %}
        {% if year == "2014" %}
            <li><p><a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a> &mdash; {{ post.date | date: "%B %d" }}</p></li>
        {% endif %}
{% endfor %}

这篇关于按年份获取Jekyll帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆