CMS Development

JRinger
Member

Pagination Issue on the Blog

Over the past two months we have been having issues with Pagination on our blog. The pages are generating -1 urls. See below:

About the pages ending in "/page/-1", they have the pattern of paginated posts that have gone too far backward (trying to view page -1). In this case, the blog's listing template doesn't remove the previous page button when viewing page/0 of the blog listing page, tag pages, or author pages.

For example, https://www.getmulberry.com/blog/tag/b2b/page/0 shows the previous page button (see screenshot). I have idenitified that this issue is coming from the HubL we are using to render the pagination on lines 94-134 of the blog-listing-new module.

 

The code can be found below. Would love some suggestions on how to fix this. 

 {% if contents.total_page_count > 1 %}
        <div class="blog-pagination pb-5">
          {% if contents.total_page_count > 0 %}
          {% if widget.range == 10 %}
          {% set base = 10 %}
          {% set loop_ = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] %}
          {% else %}
          {% set base = 5 %}
          {% set loop_ = ['1', '2', '3', '4', '5'] %}
          {% endif %}

          {% set current_pg_index = last_page_num + 1 %}
          {% set range_start = ((1 - current_pg_index) % base) + current_pg_index %}


          {% set range_end = range_start + (base)-1 %}

          {% set previous_range_start = ((6 - current_pg_index) % base) + current_pg_index - base  %}
          {% if previous_range_start < 1 %}
          {% set previous_range_start = 1 %}
          {% endif %}
          <ul>
            <li class="first-posts-link {% if current_pg_index <= 1 %}hide{% endif %}"><a href="{{ blog_page_link(1) }}"><i class="fa fa-angle-double-left"></i></a></li>
            <li class="previous-posts-link {% if !last_page_num %}hide{% endif %}"><a href="{{ blog_page_link(last_page_num) }}"><i class="fa fa-angle-left"></i></a></li>
            <span class="pg">
              {% set i = range_start %}
              {% for pg in loop_ %} {# effectively, for i=1 to i=base #}
              {% if i <= contents.total_page_count %}
              <li{% if i == current_pg_index %} class="active"{% endif %}><a href="{{ blog_page_link(i) }}">{{ i }}</a></li>

              {% set i = i + 1 %}
              {% endif %}
              {% endfor %}
            </span>
            <li class="next-posts-link {% if current_pg_index == contents.total_page_count %}hide{% endif %}"><a href="{{ blog_page_link(next_page_num) }}"><i class="fa fa-angle-right"></i></a></li>
            <li class="last-posts-link {% if current_pg_index == contents.total_page_count %}hide{% endif %}"><a href="{{ blog_page_link(contents.total_page_count) }}"><i class="fa fa-angle-double-right"></i></a></li>
          </ul>
          {% endif %}
        </div>
        {% endif %}
      </div>

 

 

0 Upvotes
3 Replies 3
alyssamwilie
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Pagination Issue on the Blog

Did you clear your cache? I just went to a few /page/0 pages and I'm not seeing the previous button anymore.

 

Screen Shot 2023-01-17 at 5.41.12 PM.png

 

 

 

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.
alyssamwilie
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Pagination Issue on the Blog

I would try changing 

{% if !last_page_num %}hide{% endif %}

to

{% if !last_page_num || current_pg_index < 1 %}hide{% endif %}

 

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.
JRinger
Member

Pagination Issue on the Blog

Thanks. I tried making this change and then crueled the site and am still having the same problem. 

0 Upvotes