I would like to create another page-based loop, in the same way the _posts folder works for the blog section, but for a small catalogue of magazines. (Hopefully that makes sense)
Maybe i’m misunderstanding something simple, but I just can’t work it out.
I have this loop, which feels like it should work, but nothing gets returned.
{% for page in site.pressitems %}
<li>
<a href="{{ post.url }}">{{ page.title }}</a>
</li>
{% endfor %}
Code, links, explanation, anything is greatly appreciated. 🙂
You can’t add your own collection to
sitejust like that.siteonly knows about three collections:pages,posts, andcategories. You can get all the posts of a category by doingsite.<category>.posts. AFAIK, categories only work for posts, not pages.This makes sense, since Jekyll is supposed to be mainly a blogging engine, and not a generic static website generator.
So your best solution right now consists on “lying” to jekyll. Make it believe you have posts, when in reality you are making pages.
You will be able to loop over the elements inside _posts/pressitems like this:
Similarly, your “real blog entries” would go this way:
The catch is that you will have to respect Jekyll’s naming convention regarding filenames; your pressitems have to look like real posts. This means they have to be named starting with a yyyy-mm-dd- string, like posts. Just give them a random date.
EDIT: This was true when this post was originally written, in 2012, but not any more. Modern Jekyll does allow you to create your own collections https://jekyllrb.com/docs/collections/