【发布时间】:2014-08-02 11:25:51
【问题描述】:
如果您愿意,我正在制作我网站上所有帖子的“存档”。我想收集一年的所有帖子。但是,此代码可以正常工作;我希望它在需要时生成<h2>2014</h2>。
基本上,如果年份是 2014 年,则渲染 <h2>2014</h2> 并制作 <ul> 来自给定的所有帖子(带有期刊类别)年。
如果有人知道任何按年存档的 .rb 插件,请告诉我!
<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> — {{ post.date | date: "%B %d" }}</p></li>
</ul>
{% endif %}
{% endfor %}
【问题讨论】: