Last active
June 4, 2021 18:33
-
-
Save Phlow/a0e3fa686eb259fe7f76 to your computer and use it in GitHub Desktop.
Jekyll: List all categories with according post count and show and link all post items listed in the according category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Categories</h2> | |
<ul> | |
{% assign categories_list = site.categories %} | |
{% if categories_list.first[0] == null %} | |
{% for category in categories_list %} | |
<li><a href="#{{ category | downcase | downcase | url_escape | strip | replace: ' ', '-' }}">{{ category | camelcase }} ({{ site.tags[category].size }})</a></li> | |
{% endfor %} | |
{% else %} | |
{% for category in categories_list %} | |
<li><a href="#{{ category[0] | downcase | url_escape | strip | replace: ' ', '-' }}">{{ category[0] | camelcase }} ({{ category[1].size }})</a></li> | |
{% endfor %} | |
{% endif %} | |
{% assign categories_list = nil %} | |
</ul> | |
{% for category in site.categories %} | |
<h3 id="{{ category[0] | downcase | url_escape | strip | replace: ' ', '-' }}">{{ category[0] | camelcase }}</h3> | |
<ul> | |
{% assign pages_list = category[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 }} <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 %} |
Let's say I don't use a default front-matter variable like tags
or categories
, but instead a non-default one like author
/ authors
in each post? I does work for categories, I have these too, but I want it for authors too.
If i replace site.categories
with site.authors
I get a Liquid Exception: 0 is not a symbol nor a string in xxx.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
when i click the category, my posts don't show up. do I have to set the permalink and create a page?
because now it just points to category/year/month/day/category