jekyll-paginate-v2 icon indicating copy to clipboard operation
jekyll-paginate-v2 copied to clipboard

Pagination doesnt work on a collection page

Open hosnas opened this issue 7 years ago • 13 comments

I want to use some of my collection pages to show pagination of other collections. but it seems this plugin doesnt support this functionality. Any reason why? and any chance it could be considered as a feature request?

hosnas avatar Mar 07 '18 13:03 hosnas

I'm currently facing the same issue, even though I've added

pagination:
  enabled: true

to the front matter of all my collection pages, the paginator won't pick it up.

Just to clarify, my site structure is as follows:

- _products
  - product1.md
  - product2.md
- _types
  - electronis.md
  - outdoor.md

_products have the following front matter

types:
  - electronics
  - outdoor

In my _types template I can easily get all the products

{% assign products = site.products | where_exp: "product", "product.types contains page.slug" %}

But how do I get pagination to work? None of the solutions or examples seem to work. I'm getting slightly confused as this doesn't seem like a unusual use-case.

woutrbe avatar Mar 22 '18 02:03 woutrbe

Hi, could you please provide me with a repro of this issue in a git repo somewhere or a zip file that I can test out. This may be a configuration that I hadn't anticipated and it is impossible to figure out why this is going wrong without being able to debug the exact issue :)

sverrirs avatar Mar 22 '18 08:03 sverrirs

I just created a new project to show my configuration: https://github.com/woutrbe/jekyll-pagination Basically I want to paginate all category pages under http://127.0.0.1:4000/categories

But a few questions:

  1. How do I do this for categories where I have a custom post list
  2. Even with pagination enabled in the layout, jekyll complains about Is enabled, but I couldn't find any pagination page.

Let me know if the example is clear enough.

woutrbe avatar Mar 22 '18 09:03 woutrbe

@sverrirs as per here collection docs aren't considered as a candidate for pagination. it means pagination can be only enabled in pages. I hope this would be enhanced to include collection docs too.

hosnas avatar Mar 22 '18 09:03 hosnas

@hosnas Isn't this already supported by AutoPages addon?

renshuki avatar Apr 04 '18 13:04 renshuki

@renshuki I don't think so. How?

hosnas avatar Apr 05 '18 06:04 hosnas

I'm having the same issue.

The collection I'm trying to paginate is called microblog. In the example below, /_microblog/index.html is not seen by jekyll-paginate-v2 even though it has pagination configuration in its front matter.

I don't see the Is enabled, but I couldn't find any pagination page. warning unless I explicitly enable pagination in the root _config.yaml, but regardless of what _config.yaml says, the pagination configuration in the front matter in /_microblog/index.html appears to be completely ignored.

Here's my setup, all relative to a top-level directory:

/Gemfile:

source 'https://rubygems.org'
gem 'jekyll'
gem 'jekyll-paginate-v2'

/_config.yml (note that there's no pagination-related configuration here):

collections:
  microblog:
    output: true
exclude: ['Gemfile', 'Gemfile.lock']
kramdown:
  entity_output: numeric
sass:
  style: compressed
  sass_dir: _sass
plugins:
- jekyll-paginate-v2

/_microblog/posts: (Contains a bunch of Markdown files)

/_microblog/index.html:

---
layout: default
title: Microblog
pagination:
  enabled: true
  collection: microblog
---
<br />

<h1>Microblog</h1>

{% for post in paginator.posts %}
  <h1>{{ post.content }}</h1>
{% endfor %}

{% if paginator.total_pages > 1 %}
<div class="pagination">
  {% if paginator.previous_page %}
    <a href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">&laquo; Prev</a>
  {% else %}
    <span>&laquo; Prev</span>
  {% endif %}

  {% for page in (1..paginator.total_pages) %}
    {% if page == paginator.page %}
      <em>{{ page }}</em>
    {% elsif page == 1 %}
      <a href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">{{ page }}</a>
    {% else %}
      <a href="{{ site.paginate_path | prepend: site.baseurl | replace: '//', '/' | replace: ':num', page }}">{{ page }}</a>
    {% endif %}
  {% endfor %}

  {% if paginator.next_page %}
    <a href="{{ paginator.next_page_path | prepend: site.baseurl | replace: '//', '/' }}">Next &raquo;</a>
  {% else %}
    <span>Next &raquo;</span>
  {% endif %}
</div>
{% endif %}

<!-- Unrelated content follows -->

I hope that's a clear example that demonstrates the issue, but I'm happy to clarify anything if needed.

@sverrirs

Edit: Had stuff left over from an autopaging experiment in my _config.yml that I didn't mean to paste here, I've removed it from the example code.

joshdick avatar Aug 16 '18 20:08 joshdick

Figured it out.

Based on my example above, my existing /_microblog/posts folder needed to only contain the Markdown files, but I needed to move index.html to /microblog/index.html to get pagination to work (as opposed to /_microblog/index.html where it was before -- no underscore.)

Other resources not mentioned in my example above that used to be in /_microblog (RSS feed, etc.) also needed to be moved to /microblog so that jekyll-paginate-v2 wouldn't try to also paginate them.

tl;dr posts need to be inside /_collectionName/posts, but the page to be paginated needs to live in /collectionName.

joshdick avatar Aug 16 '18 22:08 joshdick

@joshdick you might also need to add a string filter to remove /index.html if your _config.yml is set to expressionless urls (pretty)- which paginate v2 does not seem to honour.

<!-- PAGINATION -->
{% if paginator.total_pages > 1 %}
<div class="row">
	<div class="col-sm-12 text-center m-t-40 m-b-40">
		<ul class="pagination font-alt">
			{% if paginator.previous_page %}
			<li><a href="{{ paginator.previous_page_path | prepend: site.baseurl }}"><i class="fa fa-angle-left"></i></a></li>
			{% endif %}
			{% if paginator.page_trail %}
				{% for trail in paginator.page_trail %}
					<li {% if page.url == trail.path %}class="active"{% endif %}>
						<a href="{{ trail.path | prepend: site.baseurl | remove: "index.html" }}" title="{{trail.title}}">{{ trail.num }}</a>
					</li>
				{% endfor %}
			{% endif %}
			{% if paginator.next_page %}
				<li><a href="{{ paginator.next_page_path | prepend: site.baseurl }}"><i class="fa fa-angle-right"></i></a></li>
			{% endif %}
		</ul>
	</div>
</div>
{% endif %}
<!-- /PAGINATION -->

spero-cnet avatar Aug 16 '18 22:08 spero-cnet

@spero-cnet That indeed happened to me and your code did the trick, thanks for the tip.

joshdick avatar Aug 17 '18 05:08 joshdick

Figured it out.

Based on my example above, my existing /_microblog/posts folder needed to only contain the Markdown files, but I needed to move index.html to /microblog/index.html to get pagination to work (as opposed to /_microblog/index.html where it was before -- no underscore.)

Other resources not mentioned in my example above that used to be in /_microblog (RSS feed, etc.) also needed to be moved to /microblog so that jekyll-paginate-v2 wouldn't try to also paginate them.

tl;dr posts need to be inside /_collectionName/posts, but the page to be paginated needs to live in /collectionName.

Thank you thank you. I was having the same issue and searching all over this repo was not helping. Your comment was the only thing that cleared it up (well, your comment and taking a lunch break before deep frustration set in :) )

vcavallo avatar Jan 25 '19 18:01 vcavallo

@vcavallo You're welcome!

joshdick avatar Jan 25 '19 18:01 joshdick

Figured it out.

Based on my example above, my existing /_microblog/posts folder needed to only contain the Markdown files, but I needed to move index.html to /microblog/index.html to get pagination to work (as opposed to /_microblog/index.html where it was before -- no underscore.)

Other resources not mentioned in my example above that used to be in /_microblog (RSS feed, etc.) also needed to be moved to /microblog so that jekyll-paginate-v2 wouldn't try to also paginate them.

tl;dr posts need to be inside /_collectionName/posts, but the page to be paginated needs to live in /collectionName.

Thanks.. was stumbling upon this as well.. it did seem from #104 that it could be fixed in other ways, but couldnt get that to work

pixelicous avatar May 21 '20 09:05 pixelicous