杰基尔流动:具有职位数的输出类别列表? [英] Jekyll & Liquid: Output category list with post count?
问题描述
我不知所措,找不到正确的方法.
I'm somehow stuck and don't find the right way to do it.
我要输出一个类别列表,其中包含每个类别中的帖子数.
I want to output a category list with the number of posts in each categorie.
我到此为止: https://paste.xinu.at/dOLtod/
但是我从未设法得到真实的计数.我尝试了很多方法,但没有任何效果,例如浏览每条帖子并检查每个类别是否等于{{category |首先}}.
but I never managed to get the real count. I tried so many ways and nothing worked, for example going through each post and checked on every category if it equals {{ category | first }}.
这是没有计数的代码:
<ul class="dropdown-menu">
{% for category in site.categories %}
<li class="camelize_me">
<a href="/tags/{{category | first}}/">
{{category | first }}
<span class="badge">
<!-- Post count here -->
</span>
</a>
</li>
{% endfor %}
</ul>
有人有想法做到这一点吗?
Has anyone an idea to get this done?
推荐答案
我编写了一个代码段,该代码段不仅显示每个类别中的帖子数,还导航到被单击的特定类别的帖子.希望对您有所帮助:
I have written a code snippet that not only shows post count in each category, but also navigates to the posts of a specific category which got clicked. I hope you find it helpful:
<ul class="tag-box inline">
{% assign tags_list = site.categories %}
{% if tags_list.first[0] == null %}
{% for tag in tags_list %}
<li><a href="#{{ tag }}">{{ tag | capitalize }} <span>{{ site.tags[tag].size }}</span></a></li>
{% endfor %}
{% else %}
{% for tag in tags_list %}
<li><a href="#{{ tag[0] }}">{{ tag[0] | capitalize }} <span>{{ tag[1].size }}</span></a></li>
{% endfor %}
{% endif %}
{% assign tags_list = nil %}
</ul>
{% for tag in site.categories %}
<h2 id="{{ tag[0] }}">{{ tag[0] | capitalize }}</h2>
<ul class="post-list">
{% assign pages_list = tag[1] %}
{% for post in pages_list %}
{% if post.title != null %}
{% if group == null or group == post.group %}
<li><a href="{{ site.url }}{{ post.url }}">{{ post.title }}<span class="entry-date"><time datetime="{{ post.date | date_to_xmlschema }}" itemprop="datePublished">{{ post.date | date: "%B %d, %Y" }}</time></a></li>
{% endif %}
{% endif %}
{% endfor %}
{% assign pages_list = nil %}
{% assign group = nil %}
</ul>
{% endfor %}
这篇关于杰基尔流动:具有职位数的输出类别列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!