30

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

4 Answers 4

66

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

3
  • 4
    I just had this problem yesterday. replaced blogs.md with /blogs/index.html and it was fixed. Thanks! Jan 6, 2015 at 6:06
  • 3
    Also note there should be no permalink, as in: permalink: /blog/, specified in the page's frontmatter. Jul 7, 2016 at 2:38
  • 1
    Great answer! Also it's now explained on jekyll official page here: jekyllrb.com/docs/pagination
    – valvoline
    Mar 31, 2021 at 21:15
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.

2
  • Thanks for the tip, this was exactly my issue. Jul 25, 2015 at 17:59
  • Thanks for the tip. --watch was messing me up, too.
    – illbzo1
    Aug 31, 2015 at 0:25
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
0

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.