I want to show posts that are from a certain category. For example, going to url http://example.com/posts/programming will list all the posts that have \"programming\" as th
You could use a plugin (for that, see David Jacquel's answer)...but you can't use it if you want to host your site on GitHub Pages, because GitHub Pages supports only a few plugins, and jekyll-archives isn't one of them.
So if you can't use a plugin, AFAIK there's no other way than to create a page for each category manually.
I'm no JavaScript guru, but I'm quite sure that it's not possible to dynamically change the category with JavaScript, because Jekyll pages are compiled once and can't be changed on the fly at runtime.
But creating a new category page for each category isn't as much work as it seems.
I have a blog post here where I explain how to do it:
Separate pages per tag/category with Jekyll (without plugins)
Short version:
(I'm using tags
instead of categories
here, but both work exactly the same)
Create a special layout file /_layouts/tagpage.html
:
---
layout: default
---
{{ page.tag }}
{% for post in site.tags[page.tag] %}
-
{{ post.date | date: "%B %d, %Y" }}: {{ post.title }}
{% endfor %}
With this layout file, you need only two lines of YAML front-matter to create a new tag page, for example /tags/jekyll/index.html
:
---
layout: tagpage
tag: jekyll
---