New to Jekyll converting a WordPress blog I'm trying to add pagination to my category layout. In _layouts
directory I've created a file named category.html. I can successfully render a particular category with:
category.html:
---
layout: default
---
{% assign catName = page.title | string %}
{% for post in site.categories[catName] %}
<p>{{ post.title }}</p>
{% endfor %}
When I try to paginate a category's posts after following Jekyll's Pagination documentation:
{% for foobar in paginator.posts %}
<p>{{ foobar.title }}</p>
{% endfor %}
the code renders nothing. Upon my research Github Pages limits what plugins can be used and I cannot verify if jekyll-paginate-v2 is allowed.
My file structure:
_config.yml:
plugins:
- jekyll-feed
## - jekyll-paginate-v2
- jekyll-paginate
exclude:
- Gemfile
- Gemfile.lock
collections:
category:
output: true
defaults:
scope:
path: ""
type: category
values:
layout: "category"
paginate: 1
paginate_path: "/page:num/"
Gemfile:
gem "github-pages", group: :jekyll_plugins
group :jekyll_plugins do
gem "jekyll-feed", "~> 0.6"
## gem "jekyll-paginate-v2", "~> 1.7"
gem "jekyll-paginate"
end
Research:
For a Jekyll site on Github Page how can I create pagination for the category to render only posts for that category? This would be the equivelent to WordPress' category.php.
GitHub Pages are public web pages for users, organizations, and repositories, that are freely hosted on GitHub's github.io domain or on a custom domain name of your choice. GitHub Pages are powered by Jekyll behind the scenes, so they're a great way to host your Jekyll-powered website for free.
Paginate only paginates all posts and not by category or tag.
Paginate V2 does this even for collections. But you cannot run this plugin on Github pages (allowed plugins).
Two solutions :
publish your code in a branch, generate your site locally (or with a service like Travis Continuous Integration that is free for open source projects) and publish (or let your CI publish) your generated code in another branch.
use a modern hosting provider like Netlify that allows you to use any plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With