Closed ntot closed 8 years ago
To paginate over a specific caterogy, you put a category
setting under the paginate
key in the front matter of the page you're iterating on.
---
layout: my_layout
title: "My Site - Category: Widgets"
paginate:
category: widgets
---
{% for post in paginator.posts %}
<!-- ... do stuff ... -->
{% endfor %}
You can iterate over the union of several categories by using categories
instead of category
, and providing an array.
Edit: the same kind of syntax also works for tag
/ tags
to paginate over one or more tags (just checked).
Thank you for the quick reply @jake-low, however how do I view the widgets category in the browser? I just can't get my head around how categories work in Jekyll.
The documentation on the official site is not helpful at all and makes it even more confusing. Do I have to create new folders per category? I used the https://github.com/jekyll/jekyll-archives plugin that works a treat but then I can't make the categories paginate with octopress paginate?!
Sorry for the n00b question and appreciate your help.
Hanna
As far as I understand it, Jekyll's categories and tags are both metadata about posts (and specifically posts, not pages or collections).
Posts can have any number of categories, and any number of tags (including zero, for both attributes).
The differences between them that I'm aware of:
/:categories/:year/:month/:day/:title.html
._posts
directory inside another directory (e.g. widgets/_posts
), posts that you put in that directory automatically have that category (widgets
in this case).If you want a page, say at the URL /widgets
, that contains a list of all posts that are in the widgets
category, then you could write that page by hand by creating a widgets.html
in the root of your site. If you wanted that page to be paginated, you'd use paginate.category: widgets
in the front matter, like the example from my previous comment. In the <!-- do stuff -->
section, you'd write some HTML to render this list of posts the way you want it.
The result of this would be a /widgets
page containing the first few posts which have widgets
as one of their categories. Further posts would be at /widgets/page2
, /widgets/page3
, etc. by default (though the precise URL can be configured too, with the paginate.permalink
property.
Categories (and tags) are basically metadata that Jekyll can add to your posts (sometimes automatically, as noted above) but it's up to you to do something with that metadata (such as creating pages that index content which belongs to particular categories or tags).
If what you eventually want is to have a page (or rather, a paginated set of pages) for each and every category you've used on your site (for example, /category/X
for a list of posts that are in category X
, then you'll probably want to generate those pages.
You can do this with a gem called jekyll-archives
. It can generate archive pages automatically for years, months, days, categories, and tags. It does this using a layout that you write. I think you could combine this with the octopress-paginate
gem to paginate the auto-generated archive pages.
You'd probably want to get archives working on their own, then add pagination in afterwards.
Edit:
Whoops, I see that you already tried using jekyll-archives
. Sorry about that. I got distracted halfway through responding and lost my train of thought.
I'm not sure you can use jekyll-archives
and octopress-paginate
together, unfortunately.
From what I can tell, jekyll-archives
wants you to build an archive's layout by iterating over page.posts
, while octopress-paginate
wants you to iterate over paginator.posts
. You can't really do both at once.
Your choices seem to be:
jekyll-archives
generate them) for the categories you care aboutjekyll-archives
, but don't paginate (or paginate using javascript: rather than having truly separate pages, you could use javascript to show only a specific subrange of <li>
elements in a long <ul>
, based on a page selector).A demo of the paginate-using-javascript idea can be found in the codepen here:
@jake-low thank you so so much for taking the time to write such a detailed explanation. I find that Jekyll is really great when it comes to running a simple blog, but if you want to make things more complex (categories and tags working together) or even having two plugs in to work side by side it's very frustrating if not impossible to do.
The documentation on the official Jekyll site is very basic and not as in-depth as your explanation so again thank you. I will look at ListJS and see how I can work around it.
Thank you again! Kind regards, Hanna.
Hi, I am trying to use the paginate plugin. I have the following front matter but paginator.posts is empty.
---
layout: default
title: "my_category"
paginate:
category: my_category
---
{% for post in paginator.posts %}
<!-- Doesn't get into this loop -->
{% endfor %}
Any help will be appreciated. Thanks.
@cbsiddharth
set paginate: true
and it will start showing posts.
I still can't figure out how to setup nested properties for paginate.
There should be spaces before nested properties. Failing to add any space or adding a tab will cause unexpected behaviour. I thought python is the only merciless format conscious language.
@sahilpatel14, thanks. I will try that out.
First off, LOVE this plugin! It works like a charm... But ran into an issues that I can't solve. How do I paginate categories? I paginated my pages and collections no problems but can't get my head around doing the same with categories or even tags...
Can anyone share some insight into this? Much appreciated.. Kind regards, Hanna :)