This snippet is used to add basic numbered pagination to your blog as an alternative to the default pagination mentioned here (https://designers.hubspot.com/docs/hubl/blog-content-markup#listing-pagination).
Created by: Jason Rosa
Tags: Blog
After receiving a minimum of 25 recommendations, an entry earns the "Community Approved" badge.
Please keep in mind, all entries are community created and may not be fully supported by HubSpot.
View on:
<div class="blog-pagination">
{% set page_list = [-2, -1, 0, 1, 2] %}
{% if contents.total_page_count - current_page_num == 1 %}{% set offset = -1 %}
{% elif contents.total_page_count - current_page_num == 0 %}{% set offset = -2 %}
{% elif current_page_num == 2 %}{% set offset = 1 %}
{% elif current_page_num == 1 %}{% set offset = 2 %}
{% else %}{% set offset = 0 %}{% endif %}
<div class="blog-pagination-left">
{% if current_page_num >= 3 %}
<a class="first-link" href="{{ blog_page_link(1) }}">❮❮</a>
{% endif %}
{% if last_page_num %}<a class="prev-link" href="{{ blog_page_link(last_page_num) }}">❮</a>{% endif %}
</div>
<div class="blog-pagination-center">
{% for page in page_list %}
{% set this_page = current_page_num + page + offset %}
{% if this_page > 0 and this_page <= contents.total_page_count %}
<a {% if this_page == current_page_num %}class="active"{% endif %} href="{{ blog_page_link(this_page) }}">{{ this_page }}</a>
{% endif %}
{% endfor %}
</div>
<div class="blog-pagination-right">
{% if next_page_num %}<a class="next-link" href="{{ blog_page_link(current_page_num + 1) }}">❯</a>{% endif %}
{% if contents.total_page_count - current_page_num >= 2 %}
<a class="last-link" href="{{ contents.total_page_count }}">❯❯</a>
{% endif %}
</div>
</div>
.blog-pagination {
display: block;
text-align: center;
}
.blog-pagination > div {
display: inline-block;
}
.blog-pagination a {
color: #000;
text-decoration: none;
}
.blog-pagination-left {
text-align: right;
}
.blog-pagination-right {
text-align: left;
}
.blog-pagination a {
border-radius: 4px;
display: inline-block;
padding: 5px 10px;
text-align: center;
}
.blog-pagination a:hover,
.blog-pagination a:focus {
background-color: #c8ecff;
text-decoration: none;
}
.blog-pagination a.elipses {
border: 0;
}
.blog-pagination a.active {
background-color: #f5f5f5;
color: #666;
pointer-events: none;
cursor: default;
}
.blog-pagination a.next-link,
.blog-pagination a.prev-link,
.blog-pagination a.last-link,
.blog-pagination a.first-link{
background-color: #666;
color: #fff;
}
.blog-pagination a.next-link:hover,
.blog-pagination a.prev-link:hover,
.blog-pagination a.last-link:hover,
.blog-pagination a.first-link:hover{
background-color: #008cd4;
color: #fff;
}
Purpose: to add basic numbered pagination to a HubSpot blog.
Add this snippet in the blog content module of your listing template where you want the pagination to show.
A web developer living in Portsmouth, New Hampshire and working for @HubSpot.
View Jason Rosa’s Gallery (3 Entries)A modern framework for accelerating build times on the HubSpot CMS. Based on a modified Bootstrap 4 framework.
Lead developers: Jon McLaren
Chrome/Chromium extension for HubSpot CMS Developers that adds a developer menu, dark theme and useful shortcuts to commonly used HubSpot query parameters, resources, and tools for making HubSpot Development easier and more enjoyable.
Lead developers: Jon McLaren , William Spiro , Gonzalo Torreras
This extension enables super fast local development of CMS pages, and is a great compliment to using the new local HubL server. It contains comprehensive HubL tag, function, filter and expression test auto-complete snippets, as well as their documentation.
Lead developers: William Spiro
Find an entry with an issue, bug, or abuse?
Please complete the below information in detail and we will investigate.
Reporting as Luke Summerfield