johnnyd23
johnnyd23

Reputation: 1705

Paginate Shopify blog with offset? (Liquid)

I'm trying to figure out how to paginate a blog starting at a specific offset. For example, the first page features posts 5-8, the second page 9-12, third page 13-16, and so on. This doesn't seem to work, but I'm looking for something along these lines -

{% paginate blog.articles offset:4 by 4 %}

    {% for article in blog.articles

    ...

    {% endfor %}

{% endpaginate %}

Are there any workarounds here?

Upvotes: 2

Views: 3003

Answers (2)

Alice Girard
Alice Girard

Reputation: 2173

The offset should be specified in your loop parameters, not in pagination.

Upvotes: 1

Juan Ferreras
Juan Ferreras

Reputation: 2861

I was trying to see if there's any way I could find a decent workaround in Liquid but there isn't, since you're offsetting a full page; it'd be perfectly possible to show 5-8 on the first page, but you'd need to show 9-16 on second page and so on and so forth. I'm afraid Shopify paginate won't help you here.

There could be specific workarounds for your situation; please give us more detail and we'll see. For example, if you always want to show the four latest blog articles on every page, and leave pagination handle the rest, a possible way would be to do something as per the following:

{% for article in blogs.news.articles limit: 4 %}
  {{ article.title }}
{% endfor %}

{% paginate blog.articles by 4 %}
{% unless paginate.current_page == 1 %}
  {% for article in blog.articles %}
    {{ article.title }}
  {% endfor %}
{% endunless %}

{% include 'pagination' %}
{% endpaginate %}

So outside of any pagination go through the handle to obtain the latest 4 to feature them, and if you're not on page 1, use pagination to print 4 more articles on each page.

If not, this is one of the scenarios where you should consider exposing your own service that internally calls and retrieves articles from the Shopify API as per your needs.

Upvotes: 1

Related Questions