CMS Development

MattOnce
Colaborador(a)

Blog listing page doesn't show full post count when excluding certain tags

resolver

I am trying to hide some published posts with a tag of "Coming soon". I have followed the method used here to exclude posts with a certain tag: https://www.stephanieogaygarcia.com/hubspot-website-development/set-featured-posts-on-the-hubspot-bl...

Those posts do not appear, as expected. But the first page only lists 2 posts before listing the pagination, even though the "posts per page" setting is set to 15.  Page 2 onwards displays fine.

 

How can I fix this issue? Is it counting all posts (even excluded ones) as part of the total number of posts per page?

Listing page template code:

{% extends "../layouts/base.html" %}

{% if theme.blog.listing_page.use_sticky_nav %}
{% require_js %}
<script>
var element = document.getElementById("hhs-main-nav");
element.classList.add("hhs-alt-nav");
</script>
{% end_require_js %}
{% endif %}


{% block body %}
{% if blog_author %}
<div class="blog-header-standard" style="{% if theme.blog.listing_page.header.bg_type == 'image' %}background-image: url('{{ theme.blog.listing_page.header.bg_img.src }}');{% endif %}">
<div class="container-slim">
<div class="blog-header__inner row">
<div class="col-md-3">
{% if blog_author.avatar %}
<div class="blog-header__author-avatar" style="background-image: url('{{ blog_author.avatar }}');"></div>
{% endif %}
</div>
<div class="col-md-9">
<h1 class="blog-header__title">{{ blog_author.display_name }}</h1>
<p class="blog-header__subtitle">{{ blog_author.bio }}</p>
{% if blog_author.has_social_profiles %}
<div class="blog-header__author-social-links">
{% if blog_author.website %}
<a href="{{ blog_author.website }}" target="_blank">
{% icon name="link" style="SOLID" width="10" %}
</a>
{% endif %}
{% if blog_author.facebook %}
<a href="{{ blog_author.facebook }}" target="_blank">
{% icon name="facebook-f" style="SOLID" width="10" %}
</a>
{% endif %}
{% if blog_author.linkedin %}
<a href="{{ blog_author.linkedin }}" target="_blank">
{% icon name="linkedin-in" style="SOLID" width="10" %}
</a>
{% endif %}
{% if blog_author.twitter %}
<a href="{{ blog_author.twitter }}" target="_blank">
{% icon name="twitter" style="SOLID" width="10" %}
</a>
{% endif %}
</div>
{% endif %}
</div>
</div>
</div>
<div class="blog-header-overlay"></div>
</div>
{% else %}

{% if tag %}
<div class="blog-header post-header container oh-breadcrumb-container">
<div class="row justify-content-center">
<div class="col-lg-12"> <!-- // Was "col-lg-6"-->

<!-- New Blog breadcrumbs -->
<nav class="nav-breadcrumbs" aria-label="Blog breadcrumbs">
<ol class="oh-breadcrumbs">
<li><a class="" href="{{ group.absolute_url }}">Blog</a></li>
<li class="blog-post__tags">
<a class="blog-post__tag-link" href="#">{{ page_meta.html_title|split(' | ')|last }}</a>
</li>
</ol>
</nav>
<!-- End Blog breadcrumbs -->
</div>
</div>
</div>

{% endif %}

<div class="blog-header-standard" style="{% if theme.blog.listing_page.header.bg_type == 'image' %}background-image: url('{{ theme.blog.listing_page.header.bg_img.src }}');{% endif %}">
<div class="container">
<div class="blog-header__inner row">
<div class="col-md-8">
<h1 class="blog-header__title">{{ group.public_title }}</h1>
<h4 class="blog-header__subtitle">{{ group.description }}</h4>
</div>
<div class="col-md-4">
<div class="blog-header__form">
{% module "blog_subscribe_form" path="@hubspot/blog_subscribe", title="" %}
</div>
</div>
</div>
</div>
<div class="blog-header-overlay"></div>
</div>
{% endif %}

<div class="blog-content-body">
<div class="container">
<div class="row">
<div class="blog-index">
{% if tag %}
<div class="blog-index__tag-header">
<h5 class="blog-index__tag-subtitle">Posts about</h5>
<h3 class="blog-index__tag-heading">{{ page_meta.html_title|split(' | ')|last }}</h3>
</div>
{% endif %}
{% for content in contents %}
{% for topic in content.topic_list %}
{% if topic.name != 'Coming Soon' %}
{# Add the markup for the rest of your posts here #}
<div class="blog-index__post blog-index__post--small">
<div class="hhs-blog-card-inner">
<a class="blog-index__post-image blog-index__post-image--small"
{% if content.featured_image %}
style="background-image: url('{{ content.featured_image }}')";
{% endif %}
href="{{ content.absolute_url }}"></a>
<div class="blog-index__post-content blog-index__post-content--small">
<h2><a href="{{ content.absolute_url }}">{{ content.name }}</a></h2>
<p>{{ content.meta_description }}</p>
</div>
</div>
</div>
{% endif %}
{% endfor %}
{% endfor %}
</div>
{% if contents.total_page_count > 1 %}
<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 %}

<a class="blog-pagination__link blog-pagination__prev-link {{ "blog-pagination__prev-link--disabled" if !last_page_num }}" href="{{ blog_page_link(last_page_num) }}">
{% icon name="chevron-left" style="SOLID", width="13", no_wrapper=True %}
Prev
</a>
{% 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 class="blog-pagination__link blog-pagination__number-link {{ "blog-pagination__link--active" if this_page == current_page_num }}" href="{{ blog_page_link(this_page) }}">{{ this_page }}</a>
{% endif %}
{% endfor %}
<a class="blog-pagination__link blog-pagination__next-link {{ "blog-pagination__next-link--disabled" if !next_page_num }}" href="{{ blog_page_link(current_page_num + 1) }}">
Next
{% icon name="chevron-right" style="SOLID", width="13", no_wrapper=True %}
</a>
</div>
{% endif %}
</div>
</div>
</div>
{% endblock body %}

 

0 Avaliação positiva
1 Solução aceita
mangelet
Solução
Orientador(a) | Parceiro Platinum
Orientador(a) | Parceiro Platinum

Blog listing page doesn't show full post count when excluding certain tags

resolver

@MattOnce Consider doing a custom pagination calculation exlcuding the tag "Coming soon" too. 

 

You see contents.total_page_count is calculating the total page count with all blog posts including those tagged "Coming soon".

Martin Angeletti
HubSpot Veteran (12+ years)

Worried about messing up your HubSpot? I've got your back.

Join the thousands of people who have discovered how to avoid problems with simple tricks and have started to dominate HubSpot (and not be dominated).

️ Don't get left behind.

→ Click the subscribe button and scroll down to find the opt-in box.

Subscribe

Did I help answer your question? Mark this as a solution.

Exibir solução no post original

0 Avaliação positiva
2 Respostas 2
mangelet
Solução
Orientador(a) | Parceiro Platinum
Orientador(a) | Parceiro Platinum

Blog listing page doesn't show full post count when excluding certain tags

resolver

@MattOnce Consider doing a custom pagination calculation exlcuding the tag "Coming soon" too. 

 

You see contents.total_page_count is calculating the total page count with all blog posts including those tagged "Coming soon".

Martin Angeletti
HubSpot Veteran (12+ years)

Worried about messing up your HubSpot? I've got your back.

Join the thousands of people who have discovered how to avoid problems with simple tricks and have started to dominate HubSpot (and not be dominated).

️ Don't get left behind.

→ Click the subscribe button and scroll down to find the opt-in box.

Subscribe

Did I help answer your question? Mark this as a solution.

0 Avaliação positiva
MattOnce
Colaborador(a)

Blog listing page doesn't show full post count when excluding certain tags

resolver

Thank you, @mangelet , that sounds like exactly what I should do. Can you advice what code I might use to create a new page_count variable that excludes "Coming Soon"?

I assume I would need to set a variable that increments based on an if topic != "coming soon" statement, then divide it by the number of posts per page (15)?

 

Thanks again

0 Avaliação positiva