Closed ericvida closed 8 years ago
I managed to reverse the posts in a collection by changing line 139 in octopress-paginate.rb to read:
page.site.collections[page['paginate']['collection']].docs.reverse
Maybe add a reverse: false
to the DEFAULT
yaml front matter dictionary so one could presumably override it on a per page basis. Then on line 142 insert something like this:
if page.data['paginate']['reverse'] == true
collection = collection.reverse
end
PS. I've never written ruby in my life so I have no idea if that works
That sounds awesome shawn. So How do I implement this? I'm not too ruby savvy yet.
I forked paginate
and added what I mentioned above to octopress-paginate.rb
. Specifically line 16 and more lines starting at 143. This was just a little causal hacking, be aware that this might break other things. I have submitted a pull request.
@shawnthroop @iamtirado Has this been merged at all? Any testing needed to get it merged?
@imathis Have you been able to look into this yet? Shawnthroop's pull request looks like it works.It'd be helpful to me right now. I built a site for work which has been live for almost a year now and this is the only feature I'm waiting to activate.
Thanks @shawnthroop. I do it. and it works.
So file in Linux
located somewhere like here:
/usr/local/lib/ruby/gems/2.3.0/gems/octopress-paginate-1.1.2/lib/octopress-paginate.rb
And here what i do:
cd /usr/local/lib/ruby/gems/2.3.0/gems/octopress-paginate-1.1.2/lib/
sudo gedit octopress-paginate.rb
page.site.collections[page['paginate']['collection']].docs
to page.site.collections[page['paginate']['collection']].docs.reverse
And inindex.html
's liquid, don't use reversed
in for loop
. write for loop
like this:
{% for post in paginator.Posts_en %}
@parkr: this should be fixed by #12.
Maybe there's a proper way of doing this with octopress-paginate that's not yet documented, but so far I'm just trying use octopress-paginate as I would use the "reverse" feature of jekyll's pagination.
Pagination reverse is really important, because for most types of blogging or content sharing, the latest products, news, and posts are the most relevant and should display first on a list.
What Should Happen
Reversed pagination generates the latest content to appear as first on a stack list rather than last. When pagination splits content into multiple pages.
Let's say my page is set to paginate 5 items per page, and I have a total of 10 items, it should look like this:
Page1: [Item 1, 2, 3, 4, 5] Page2: [Item 6, 7, 8, 9, 10]
With pagination reversed, it should look like this: Page1: [Item 10, 9, 8, 7, 6] Page2: [Item 5, 4, 3, 2, 1]
But with octopress-paginate, "reverse" happens like this: Page1: [Item 5, 4, 3, 2, 1] Page2: [Item 10, 9, 8, 7, 6]
What Actually Happens
It seems like it brakes them up into pages before reversing the other, so the first 5 posts are still on the first page, but reversed in order, and the latest 5 posts are still in the 2nd page.
Example Code
Here's an example of my reversed paginated collection loop.
I can't wait to learn how to fix these issues myself, make pull requests and help you guys out.