Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paginate Collections #3

Closed
parkr opened this issue Jul 1, 2014 · 29 comments
Closed

Paginate Collections #3

parkr opened this issue Jul 1, 2014 · 29 comments

Comments

@parkr
Copy link
Member

parkr commented Jul 1, 2014

Allow users to paginate collections!

@rachelnabors
Copy link

Voting yay on this.

@sarhov
Copy link

sarhov commented Aug 14, 2014

+1

@jeromecoupe
Copy link

+1 pretty please. One of my biggest frustrations with Jekyll would be solved by this. In most cases You can do without pagination but sometimes it would be quite handy (ton of content)

@parkr
Copy link
Member Author

parkr commented Aug 27, 2014

Thanks for the +1's. How would you envision pagination working?

@binoyte
Copy link

binoyte commented Sep 21, 2014

+1 for that definitly!
+1 for paginate categories

@TooGz
Copy link

TooGz commented Sep 22, 2014

Vote for it :)

@kleinfreund
Copy link

👍

@jeromecoupe
Copy link

As far as the technical implementation, I don't have a clue but, since pagination should ideally be available in multiple places (posts, collections, categories), I guess you'd have to go beyond the existing paginator variable.

Ideally (and this is probably very difficult to implement), I'd like a looping tag pair that you could then use with any array / object (post / collections / categories). Something along the lines of:

provided you have an _albums collection

{% paginate site.albums as albums limit:5 %}

  {% for album in albums %}
    ... display album data ...
  {% endfor %}

  {% if paginate.previous %}
    <a href="{{ paginate.previous_path | prepend: site.baseurl | replace: '//', '/' }}">Previous</a>
  {% endif %}

  {% if paginate.next %}
    <a href="{{ paginate.next_path | prepend: site.baseurl | replace: '//', '/' }}">Next</a>
  {% endif %}

{% endpaginate %}

@ziyan-junaideen
Copy link

I agree with @jeromecoupe. Great idea 👍 . Can try to give some help my self but will take time because I am just 2 days old for Jekyll

@garethredfern
Copy link

Would love to see this.

@sambaldwin
Copy link

👍 I would also love to see this.

@marianoviola
Copy link

👍 sounds good.

@parkr
Copy link
Member Author

parkr commented Nov 25, 2014

Happy to look at a PR :)

@sambaldwin
Copy link

Not sure if this is too off-topic, but since I arrived here via Google looking for a solution to collection pagination, I figured I'd post a workaround incase anyone else was in the same boat as me.

It is possible to manually paginate using both limit and offset on the for loop.

My code:

{% for item in items limit:10 %}

And then in a manually created page-2.html file:

{% for item in items limit:10 offset:10 %}

page-3.html:

{% for item in items limit:10 offset:20 %}

etc.

@swashcap
Copy link

swashcap commented Feb 9, 2015

👍

@daveaseeman
Copy link

+1 for the solution proposed by @jeromecoupe (kudos to @sambaldwin for an easy work-around but I'm 100% in favor of making this a more universal feature)

@bjfish
Copy link

bjfish commented Feb 18, 2015

👍

3 similar comments
@rachelnabors
Copy link

👍

@jorgebg
Copy link

jorgebg commented Mar 10, 2015

👍

@rhewitt22
Copy link

👍

@parkr parkr closed this as completed Jun 15, 2015
@TWiStErRob
Copy link

@parkr why was this closed? Where's the work on collection pagination, if any, being tracked in future?

@stammy
Copy link

stammy commented Jul 25, 2015

Add me as interested in this as well :)

@rachelnabors
Copy link

And me.

@sarhov
Copy link

sarhov commented Jul 26, 2015

I also didn't understand why the issue is closed ...

@gynter
Copy link

gynter commented Jul 26, 2015

Because jekyll-paginate will be discontinued, more info in forum.

@TWiStErRob
Copy link

Thanks @gynter, please note that the issue was closed a month ago, while that announcement was done 10 hours ago. So it's clear now it, but we can agree it was a weird timeline of communication.
It would be nice to update the README.md with a deprecation notice with a link to that forum and later a link to replacement, thanks again!

@Fallenstedt
Copy link

Fallenstedt commented Oct 17, 2016

You can include pagination by including some liquid logic into the layout of your collection.
For example, I have a collection called "_portfolios" where I will hold all of my portfolio items. Each portfolio item has yml like this:

`---
title: Landscape
subtitle: Photography
layout: portfolio

cta:
btnText: View Services
btnType: btn-warning
btnLink: /about/

images:

  • /images/landscape/landscape-8.jpg
  • /images/landscape/landscape-4.jpg
  • /images/landscape/landscape-1.jpg
  • /images/landscape/landscape-2.jpg
  • /images/landscape/landscape-3.jpg
    ---`

In layouts > portfolio.html I have the following includes to use a widget I made:

{% include collection-pagination.html collection="portfolios" %}

The liquid logic in collection-pagination.html is:

`
{% assign this_collection = include.collection %}
{% for c in site.[this_collection] %}
{% 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.[this_collection] %}
{% 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.[this_collection] %}
{% 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 %}


{% if prevPost.url %}
previous
{% endif %}

{% if nextPost.url %}
next
{% endif %}

`

This generate two buttons that you can style. The neat part is that if you are at the first item of the collection, the "previous" button will be disabled and hidden. If you are at the last item of a collection, the "next" button will be disabled.

I learned about this from: anjesh.github.io/2015/01/25/collection-pagination-working-github-pages/

@wysiwyggins
Copy link

I've been trying to paginate a masonry layout image-board that iterates through every file in an image folder and it feels way more complicated than it should be... I've been using paginate v2

@ashmaroli
Copy link
Member

@Weevil Paginate v2 is a different project entirely:
https://github.com/sverrirs/jekyll-paginate-v2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests