I have a jekyll website and I have a category (called photo
) and I wanted to create a separate layout for a page that would list just the posts that were in the photo
category. I also want to keep posts with the photo
category out of the main index page.
Asked
Active
Viewed 1.0k times
22

Mark Szymanski
- 56,590
- 24
- 70
- 87
3 Answers
34
All categories are available within the site object, access the posts of a category via site.categories.photo
so your loop would look like this
{% for post in site.categories.photo %}
# render the photo post html
{% endfor %}

David Burrows
- 5,217
- 3
- 30
- 34
-
Unless I misunderstand the question, this should be the correct answer. – matb33 Nov 12 '12 at 14:37
-
Indeed. Correct, but a bit late. – Janusz Lenar Dec 19 '12 at 14:31
-
@matb33 I.e. later than a quarter, heh. – Janusz Lenar Dec 19 '12 at 14:32
-
I prefer this solution, but that is just me :) – Tim B James Feb 08 '13 at 22:00
-
2@matb33 not the full answer because he will still have the `photo` posts in his main index page – Ali Almoullim Apr 13 '15 at 02:53
24
I just used an {% unless %}
block in the main index page to make sure the post wasn't a photo. Example:
{% unless post.category == "photo"%}
{% comment %} List posts... {% endcomment %}
{% endunless %}
And I used the same thing for showing only photos. Just with an if
instead of unless
.

Mark Szymanski
- 56,590
- 24
- 70
- 87
-
I cannot find any information on the `unless` tag. Is it still supported? – orschiro Dec 12 '13 at 20:23
-
@orschiro check the Liquid documentation: https://github.com/Shopify/liquid/wiki/Liquid-for-Designers#tags – blockloop Feb 10 '14 at 01:27
4
The category is case sensitive as well. If your category is photo then it will look like this:
{% for post in site.categories.photo %}
# render the photo post html
{% endfor %}
If your category is Photo then it will look like this:
{% for post in site.categories.Photo %}
# render the photo post html
{% endfor %}
Just a quick detail that I tripped up on my build so I thought I would share.

Trevor Glass
- 390
- 5
- 10