So i have been playing around with Octopress for a few weeks now and i love it. While creating this site, i bumped into a small problem.
How do i display a category page with a preview of all the blog posts and include pagination in it as well ?
Ofcourse, if you just want to visit the default category page that Octopress creates, you can just append something like /categories/[category_name]/ to the base url. For e.g here is the link to the posts with the category security. But this is so boring. It would have been cool to have a preview of each post just like the home page, and that also had pagination, something like this .
Here is how i did it.
First of all, create a new page that will serve all the posts for that category. Let’s assume that category name is Travel.
---
layout: default
---
{% include header.html %}
<divclass="blog-index"> {% assign index = true %}
{% for post in paginator.posts %}
{% assign content = post.content %}
<article> {% include article.html %}
</article> {% unless post == paginator.posts.last %}
<hr> {% endunless %}
{% endfor %}
<divclass="pagination"> {% if paginator.next_page %}
<aclass="prev"href="{{paginator.next_page}}">← Older</a> {% endif %}
{% if paginator.previous_page %}
<aclass="next"href="{{paginator.previous_page}}">Newer →</a> {% endif %}
</div></div>
The only change that needs to be done is that instead of iterating over all the pages, we will have to iterate over the posts of a specific category. So basically you replace paginator.posts with site.categories.security where security is the category name. Here is how it will look like.