FROM CACHE - en_header

Pagination not working with selected blogs

EmanuelVT
Shopify Partner
16 2 7

Hello, so in my theme I have a blog page in which pagination is working just fine when the default blog is selected, but when users select a blog via the blog input, pagination stops working properly. By that I mean, if I define the limit of each page to be 8 articles and I have a blog with 9 articles, the blog displays on page 1 the whole 9 articles and on page 2 the whole 9 articles again. Instead of showing 8 articles in page 1 and 1 in page 2. Again, pagintation works perfectly when they don't select a blog, but when they do, that's when it's stops working.

 

Here's my code:

{% if section.settings.featured_blog != blank %}
{% assign blog = section.settings.featured_blog  %}
{% endif %}


{%- paginate blog.articles by 8 -%}
<section class="blogs">
  <div class="container">
    <div class="blogs__header">
      <p class="blogs__header-category"></p>
      <h2 class="blogs__header-title">{{blog.title}}</h2>
      <h3>{{blog}}</h3>
    </div>
    <div class="blogs__posts">
      <div class="row">
        {%- for article in blog.articles -%}
        <div class="col-md-3 blogs__post"><a href="{{article.url}}" class="blogs__post-link">
            <div class="blogs__post-image-box">

              {% if article.image != blank %}
              <img src="{{article.image | img_url: '1500x'}}" class="blogs__post-image">
              {% else %}
              <img src={{"https://i.ibb.co/VDnQ8Qs/article-img.jpg"}} class="blogs__post-image">

              {% endif %}


            </div>
            <h3 class="blogs__post-title">{{article.title}}</h3>
            <p class="blogs__post-date">{{article.created_at | date: "%b %d, %y"}}</p>
          </a></div>
        {%- endfor -%}
      </div>

    </div>


  </div>


  {%- if paginate.pages > 1 -%}
  {%- render 'pagination', paginate: paginate -%}
  {%- endif -%}

</section>
{%- endpaginate -%}

I really don't understand why pagination works fine with the default blog but not with a selected blog.

Anyways, thanks for the help!

Replies 0 (0)