I have a folder of markdown files each with a number of key/values. I need to filter all of the markdown files in the _faq
folder by the key faq_category
.
I have tried:
{% assign post = site.faqs | where: "faq_category", name-of-category %}
<ul>
<li>{{ post.title }}</li>
</ul>
However, this is showing nothing in the end.
The folder structure it should be looping through is:
jekyll
|
--faqs
|
--name-of-faq
--name-of-faq-2
Sample markdown file:
title: name of faq
faq_id: 2567
slug: title-of-faq
created: Mar 6, 2017
modified: Mar 6, 2017
faq_category: how to fly
Instead of site.faqs
use site.posts
to get an array of posts.
Then put the markdown files in the folder: /faqs/_posts/
for example: /faqs/_posts/faq1.md
.
After that you should be able to browse them like:
{% for post in site.posts %}
{{post.title}}
{% endfor %}
To filter a specific category use: site.categories.CATEGORY
or filter them like: (for example the category "mycategory")
<ul>
{% for post in site.faqs %}
{% if post.categories contains "mycategory" %}
<li>{{ post.title }}</li>
{% endif %}
{% endfor %}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.