Jekyll Paginator not working
Asked Answered
N

4

33

I am currently working on a jekyll based homepage and I cant get pagination working.

<ul class="posts">
    {% for post in paginator.posts %}
        <li>
            <span class="list_date">{{ post.date | date_to_string }}</span> &raquo; <span class="list_title"> {{ post.title }} </span><br>
            <span class="list_content">{{ post.content | strip_html | truncatewords:35}}</span> 
            <a href="{{ post.url }}">more...</a>
        </li>
    {% endfor %}
</ul>

This is my liquid code and it works perfectly well when using site instead of paginator. Also in my _config.yml I have this part:

paginate: 2
paginator_path: "news/page:num"

Since the index.html file is in the news folder

Noah answered 29/12, 2013 at 19:9 Comment(0)
S
70

Pagination in Jekyll only works in an index.html file. If you have other pages in the root of your project folder (say, about.html, poems.html) pagination will NOT work in them.

To have pagination work in another page other than your index.html, create a new folder for that page (say, poems/) and change what would have been "poems.html" to "poems/index.html". After that, your "paginate_path" in _config.yml should be 'paginate_path: "poems/page:num/"'.

I'm still investigating this issue. My site needs pagination on multiple pages...something which Jekyll doesn't seem to support out-of-the-box

Stochastic answered 19/11, 2014 at 11:43 Comment(3)
I just had this problem yesterday. replaced blogs.md with /blogs/index.html and it was fixed. Thanks!Scotney
Also note there should be no permalink, as in: permalink: /blog/, specified in the page's frontmatter.Bim
Great answer! Also it's now explained on jekyll official page here: jekyllrb.com/docs/paginationAbirritate
S
14

I encountered a similar problem using Jekyll with the --watch autoreload feature. My issue was that the configuration wasn't being updated automatically:

Auto regeneration is not working with _config.yml?

After restarting Jekyll manually, the new configuration in _config.yml regarding the pagination was loaded and the paginator started working.

Also you appear to be declaring paginator_path while the documentation states it should be called paginate_path.

Scattering answered 26/3, 2014 at 12:21 Comment(1)
Thanks for the tip. --watch was messing me up, too.Scottiescottish
H
2

This problem has been fixed in version 2 of jekyll-paginator. Now you can use paginator in any page just run:

gem install jekyll-paginate-v2
Helmuth answered 11/12, 2018 at 15:23 Comment(1)
V2 Doesn't work with github pagesNaivete
P
2

My few cents to @wsgeorge answer. Assuming that you installed jekyll-paginate not jekyll-paginate-v2

  1. Remember to rename index.md to index.html

  2. Add paginate: true to index.html

    ---
    layout: home
    paginate: true
    ---
    
  3. Add following to _config.yaml

    paginate: 5
    paginate_path: ./page:num/
    

    Notice: . (period) in ./page:num/ path - this indicates that my index.html file is in the root directory (directory along/next to Gemfile).

Preparator answered 22/11, 2021 at 18:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.