Search code examples
jekyllliquidjekyll-extensionsjekyll-paginator

Jekyll paginate: offset offsetting all pages, not just first


I've run into an issue when using Jekyll (which uses the Liquid templating language), the plugin jekyll-paginate-v2 and offset.

The problem: I have a featured section on my blog that always shows the most recent post. The other posts appear below, 10 per page using paginate.

I tried to simply show them using {% for post in paginator.posts offset:1 %}, but this is flawed in two ways:

  • it only shows 9 posts per page instead of 10
  • it offsets the first post on each page, so that the 1st, 10th, 20th, etc. posts are hidden, which is not what I want

What I'm trying to achieve: a loop that always ignores the post at index 0 and shows everything else as it normally would.

Am I just using offset wrong, or is this a bug in jekyll-paginate-v2?

Right now I've "fixed" it by doing the following, but it's not ideal as the first page only shows 9 posts:

<div class="articles-showcase row post-list">
{% assign featuredpost = site.posts.first %}
  {% for post in paginator.posts %}
  {% if post == featuredpost %}
  {% continue %}
  {% else %}
  <!-- Article Card -->
  <div class="article-detail-box col-lg-6 col-md-6 col-sm-12 card-article-div" data-cat="{{post.category | join: ','}}">
    <div class="card card-article box-shadow h-100">
      <a href="{{ site.baseurl }}{{post.url}}" class="card-article-linker" title="{{post.title}}"></a>
      <div class="img-div text-center post-card-header bg-gray">
        <img src="{{ site.baseurl }}{{post.image}}" alt="{{post.title}}">
      </div>
      <div class="card-article-body">
        <p class="author-name">{{post.author}} | {{ post.date | date: '%B %d, %Y' }}</p>
        <a href="{{site.baseurl}}{{post.url}}">
          <h5>{{post.title}}</h5>
        </a>
        <div class="article-description">{{post.content}}</div>
      </div>
    </div>
  </div>
  {% endif %}
  {% endfor %}
</div>

Solution

  • I raised this as an issue to the jekyll-paginate-v2 developers, and it has now been solved: https://github.com/sverrirs/jekyll-paginate-v2/issues/100