在这个问题上摸不着头脑 - 非常感谢.
我想显示按类别组织的所有Jekyll帖子的列表.我知道第3行不正确,但我无法弄清楚应该是什么.有任何想法吗?谢谢!
{% for category in site.categories %}
<h3>{{ category | first }}</h3>
{% for post in page.categories.category %}
{{ post.title }}<br>
{% endfor %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
Ale*_*x G 66
得到它了!在列出个别帖子之前需要一个中间帖子循环
<ul>
{% for category in site.categories %}
<li><a name="{{ category | first }}">{{ category | first }}</a>
<ul>
{% for post in category.last %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
Run Code Online (Sandbox Code Playgroud)
tim*_*tim 20
fyi,如果有人想只列出一个类别的帖子,这是有效的(与上面的例子不同,因为该类别返回一个帖子列表...
<p>Posts in category "basic" are:</p>
<ul>
{% for post in site.categories.basic %}
{% if post.url %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endif %}
{% endfor %}
</ul>
Run Code Online (Sandbox Code Playgroud)
现在有一个官方插件可用于此。jekyll-archives。
为了利用它,
添加jekyll-archives到您的Gemfile和_config.yml文件中。
根据您的需要添加类似于下面的配置。
jekyll-archives:
enabled: all
layouts:
year: archive/year
month: archive/month
day: archive/day
tag: archive/tag
category: archive/category
permalinks:
year: '/:year/'
month: '/:year/:month/'
day: '/:year/:month/:day/'
tag: '/tags/:name/'
category: '/category/:name/'
Run Code Online (Sandbox Code Playgroud)
可以layouts根据archive type.
year,,,,,, )monthdaytagcategoryNil否则。)page.type您应该解析出日期和月份字段)这是基于年份的存档布局示例
<h1>Archive of posts from {{ page.date | date: "%Y" }}</h1>
<ul class="posts">
{% for post in page.posts %}
<li>
<span class="post-date">{{ post.date | date: "%b %-d, %Y" }}</span>
<a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
</li>
{% endfor %}
</ul>
Run Code Online (Sandbox Code Playgroud)