I have some categories, one of those categories is “bootstrap” I want to display only those posts with the category “bootstrap” on the /categories/bootstrap/ page. I have it set up so I can go to /categories/ and see all my categories. How do I get just the posts with the category “bootstrap” to show up on the bootstrap page?
I tried hitting site.categories.bootstrap in my for loop but nothing shows up?
{% for post in site.categories.bootstrap %}
What do I need to do to get just certain ones to show on a page? I do have the _categories/bootstrap.md and other example post categories in my site so I am not sure what is going on?
This is not the “correct” way, it is showing all titles on all category pages. I still need help
{% for post in site.posts %}
{% for category in site.categories %}
{% if category.name == "bootstrap" %}
- {{post.title}}
{% endif %}
{% endfor %}
{% endfor %}
On a category page:
{% for post in site.posts %}
{% if post.category == page.slug %}
- {{post.title}}
{% endif %}
{% endfor %}
That doesn’t work. Nothing is displayed on the page.
Let me find you the right code… one moment.
EDIT: I have updated the previous answer.
That doesn’t seem to work either. I can get all posts to show up using this:
{% for post in site.posts %}
{% for category in site.categories %}
{% if category.name == page.slug %}
#### [{{post.title}}]({{post.url}})<br/><small>{{ post.date | date_to_long_string }}</small>
By: {{post.author}}
{% endif %}
{% endfor %}
{% endfor %}
and the header template on a sample post is like:
---
layout : post
title : "Sample Blog Post"
fid : 50
date : "2023-02-26"
author : yosileyid
categories : ['bootstrap', 'jekyll']
---
I don’t know why I can’t get it to work lol it is a pain.
I was finally able to get it to work using this:
{% for post in site.posts %}
{% if post.categories contains 'bootstrap' %}
#### [{{post.title}}]({{post.url}})<br/><small>{{ post.date | date_to_long_string }}</small>
By: {{post.author}}
{% endif %}
{% endfor %}
I was assuming a post had just one category. Glad you found it!
1 Like