Reputation: 1200
As per Jekyll's doc, pagination for collections is not supported. I've tried to mimic Jekyll posts folder structure for my portfolio collection and then apply a slightly modified pagination Liquid syntax to work with a portfolio collection with no avail.
Is there a way/workaround in order to set up pagination for Collections in a Jekyll site?
Upvotes: 0
Views: 1924
Reputation: 969
There is a way to assign prev and next tags to "fake" pagination for your collections. Here is how anjesh did it:
{% for c in site.tripcollection %}
{% if c.title == page.title %}
{% assign thisPost = c %}
{% if forloop.index == 1 %}
{% assign prevflag = 0 %}
{% assign nextflag = 1 %}
{% elsif forloop.index == forloop.length %}
{% assign prevflag = 1 %}
{% assign nextflag = 0 %}
{% else %}
{% assign prevflag = 1 %}
{% assign nextflag = 1 %}
{% endif %}
{% endif %}
{% endfor %}
{% for c in site.tripcollection %}
{% if c.title == page.title %}
{% assign prevflag = 0 %}
{% endif %}
{% if prevflag == 1 %}
{% assign prevPost = c %}
{% assign page.previous = c %}
{% endif %}
{% endfor %}
{% if nextflag == 1 %}
{% for c in site.tripcollection %}
{% if foundPost == 1 %}
{% assign getNext = 1 %}
{% endif %}
{% if c.title == page.title %}
{% assign foundPost = 1 %}
{% endif %}
{% if getNext == 1%}
{% assign nextPost = c %}
{% assign page.next = c %}
{% assign foundPost = 0 %}
{% assign getNext = 0 %}
{% endif %}
{% endfor %}
{% endif %}
<div id="post-nav">
<div >
{% if prevPost.url %}
<a class="prev" href="{{prevPost.url}}">
<span>< {{prevPost.title}}</span>
</a>
{% endif %}
{% if nextPost.url %}
<a class="next" href="{{nextPost.url}}">
<span>{{nextPost.title}} ></span>
</a>
{% endif %}
</div>
</div>
You can read his whole post here: Get Pagination working in Jekyll Collection in Github pages
Upvotes: 4
Reputation: 52819
jekyll-paginate only paginate posts.
If you want to paginate collections, you can use Octopress Paginate but it's not supported by github (for now).
Upvotes: 2