# Displaying Related Posts Problem

**URL:** <https://community.hubspot.com/t/displaying-related-posts-problem/76127>\
**Category:** CMS Development\
**Created:** [February 28, 2023, 9:18am UTC](https://community.hubspot.com/t/displaying-related-posts-problem/76127 "2023-02-28T09:18:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MSaliba5](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@MSaliba5](https://community.hubspot.com/u/MSaliba5)\
**Post date:** [February 28, 2023, 9:18am UTC](https://community.hubspot.com/t/displaying-related-posts-problem/76127/1 "2023-02-28T09:18:52Z")

</div>

I am working on a template and I have a blog related post module.

I want to show only 3 related blog posts. The filter can be also set form the the module’s gui interface, but to be sure, I altered the module’s code to limit the number of related blog posts to 3.

My problem is that wehn I test the module by previewing the module from the Design Tools it works properly and shows 3 related blog posts. When I am testing my website, some blog posts show 3 related blogs, but some others only show 2 related blogs.

Am I missing something? Thank you!

{# Column Count Large Screens #}

{% if module.layout\_choice.select\_layout ==‘card’ %}  
{% set layoutChoice = ‘mwb-blog-related-posts\_\_card’%}  
{% elif module.layout\_choice.select\_layout ==‘card\_without\_image’ %}  
{% set layoutChoice = ‘mwb-blog-related-posts\_\_content-card’%}  
{% elif module.layout\_choice.select\_layout ==‘compact’ %}  
{% set layoutChoice = ‘mwb-blog-related-posts\_\_compact’%}  
{% endif %}

{# Column Count Large Screens #}

{% if module.column\_count.desktop ==‘two’ %}  
{% set columnCountDesktop = ‘mwb-blog-related-posts\_\_col-two’%}  
{% elif module.column\_count.desktop ==‘three’ %}  
{% set columnCountDesktop = ‘mwb-blog-related-posts\_\_col-three’%}  
{% endif %}

{# Column Count Medium Screens #}

{% if module.column\_count.tablet ==‘two’ %}  
{% set columnCountTablet = ‘mwb-blog-related-posts\_\_col-two-tb’%}  
{% elif module.column\_count.tablet ==‘three’ %}  
{% set columnCountTablet = ‘mwb-blog-related-posts\_\_col-three-tb’%}  
{% endif %}

{% set blog = module.blog %}  
{% if module.layout\_choice.select\_layout ==‘card’ %}  
{% set contents = blog\_recent\_posts(blog, 6 ) %}  
{% elif module.layout\_choice.select\_layout ==‘card\_without\_image’ %}  
{% set contents = blog\_recent\_posts(blog, 6 ) %}  
{% elif module.layout\_choice.select\_layout ==‘compact’ %}  
{% set contents = blog\_recent\_posts(blog, 5 ) %}  
{% endif %}

{% macro related\_posts(post, count, total) %}  
{% if count == 1 %}

{% if module.custom\_id.enable\_custom\_id || module.animation.enable %}  
\<div {% if module.custom\_id.enable\_custom\_id %} id=“{{ module.custom\_id.id\_name }}” {% endif %} {% if module.animation.enable %} class=“aos-container”{% endif %}\>  
{% endif %}  
\<div class=“mwb-blog-related-posts {% if module.animation.enable %} aos--active {% endif %}” {% if module.animation.enable %} data-aos=“{{ module.animation.animation.type }}” data-aos-easing=“{{ module.animation.animation.effect }}” data-aos-duration=“{{ module.animation.animation.duration }}”{% endif %}\>  
\<div class=“content-wrapper”\>  
\<div class=“mwb-blog-related-posts\_\_head”\>  
\<h5 class=“mwb-tc\_\_mini-title”\>  
{{ module.section\_head.mini\_title }}  
\</h5\>  
\<h2\>  
{{ module.section\_head.section\_title }}  
\</h2\>  
\</div\>  
\<div class=“mwb-blog-related-posts\_\_row {{ columnCountDesktop }} {{ columnCountTablet }} {{ layoutChoice }} “\>  
{% endif %}  
{% if module.layout\_choice.select\_layout !=‘card\_without\_image’ %}  
\<div class=“mwb-blog-related-posts\_\_column”\>  
\<div class=“mwb-blog-related-posts\_\_img”\>  
\<a href=”{{ post.absolute\_url }}” aria-label=“{% if post.featured\_image\_alt\_text %} Featured image: {{ post.featured\_image\_alt\_text }} - {% endif %}Read full post: {{ post.name }}”\>  
\<img src=“{{ post.featured\_image }}” loading=“lazy” width=“352” alt=“{{ post.featured\_image\_alt\_text }}”\>  
\</a\>  
\</div\>  
\<div class=“mwb-blog-related-posts\_\_content”\>  
\<div class=“mwb-blog-related-posts\_\_author”\>  
\<div class=“mwb-blog-related-posts\_\_author-detail”\>  
\<span class=“mwb-blog-related-posts\_\_blog–date”\>  
{{ datetimeformat(post.publish\_date\_local\_time, ‘%e %B %Y’) }}  
\</span\>  
\<span class=“mwb-blog-related-posts\_\_author–name”\>  
BY \<a href=“{{ blog\_author\_url(group.id, post.blog\_post\_author.slug) }}”\>{{ post.blog\_post\_author.display\_name }}\</a\>  
\</span\>  
\</div\>  
\</div\>  
\<h5 class=“mwb-blog-related-posts\_\_title”\>  
\<a href=“{{ post.absolute\_url }}”\>{{ post.name }}\</a\>  
\</h5\>  
\</div\>  
\</div\>  
{% elif module.layout\_choice.select\_layout ==‘card\_without\_image’ %}  
\<div class=“mwb-blog-related-posts\_\_column”\>  
\<div class=“mwb-blog-related-posts\_\_content”\>  
\<h5 class=“mwb-blog-related-posts\_\_title”\>  
\<a href=“{{ post.absolute\_url }}”\>{{ post.name }}\</a\>  
\</h5\>  
\<div class=“mwb-blog-related-posts\_\_author”\>  
\<div class=“mwb-blog-related-posts\_\_author-detail”\>  
\<span class=“mwb-blog-related-posts\_\_blog–date”\>  
{{ datetimeformat(post.publish\_date\_local\_time, ‘%e %B %Y’) }}  
\</span\>  
\<span class=“mwb-blog-related-posts\_\_author–name”\>  
BY \<a href=“{{ blog\_author\_url(group.id, post.blog\_post\_author.slug) }}”\>{{ post.blog\_post\_author.display\_name }}\</a\>  
\</span\>  
\</div\>  
\</div\>  
\</div\>  
\</div\>  
{% endif %}  
{% if count == total %}  
\</div\>  
\</div\>

\</div\>

{% if module.custom\_id.enable\_custom\_id || module.animation.enable %}  
\</div\>  
{% endif %}

{% endif %}  
{% endmacro %}

{% if module.layout\_choice.select\_layout ==‘card’ %}

{% related\_blog\_posts  
limit=3,  
no\_wrapper=True,  
post\_formatter=“related\_posts”  
%}

{% elif module.layout\_choice.select\_layout ==‘card\_without\_image’ %}

{% related\_blog\_posts  
limit=3,  
no\_wrapper=True,  
post\_formatter=“related\_posts”  
%}

{% elif module.layout\_choice.select\_layout ==‘compact’ %}

{% related\_blog\_posts  
limit=5,  
no\_wrapper=True,  
post\_formatter=“related\_posts”  
%}

{% endif %}

{% require\_css %}  
\<style\>  
{% scope\_css %}

.mwb-blog-related-posts\_\_content-card .mwb-blog-related-posts\_\_column {  
background: rgba({{ module.style.content\_card.hyphen\_color.color|convert\_rgb }},{{ module.style.content\_card.hyphen\_color.opacity/100 }});  
}

.mwb-blog-related-posts\_\_img a:after {  
background: linear-gradient({{ module.style.image\_gradient.angle }}deg, rgba({{ module.style.image\_gradient.first\_color.color|convert\_rgb }},{{ module.style.image\_gradient.first\_color.opacity/100 }}) {{ module.style.image\_gradient.to }}%, rgba({{ module.style.image\_gradient.second\_color.color|convert\_rgb }},{{ module.style.image\_gradient.second\_color.opacity/100 }}) {{ module.style.image\_gradient.from }}%);  
}

.mwb-blog-related-posts\_\_author-detail:before {  
background: rgba({{ module.style.hyphen\_color.hyphen\_color.color|convert\_rgb }},{{ module.style.hyphen\_color.hyphen\_color.opacity/100 }});  
}

.mwb-blog-related-posts\_\_card .mwb-blog-related-posts\_\_column,  
.mwb-blog-related-posts\_\_content-card .mwb-blog-related-posts\_\_column {  
margin-bottom: {{ module.style.posts\_bottom\_spacing.bottom\_spacing\_mobile\_ ~ ‘px’ }};  
}

{% if module.style.overwrite\_content\_styles %}  
.mwb-blog-related-posts\_\_title a,  
.mwb-blog-related-posts\_\_author-detail span,  
.mwb-blog-related-posts\_\_author-detail a {  
color: rgba({{ module.style.content\_styling.color.color|convert\_rgb }},{{ module.style.content\_styling.color.opacity/100 }});  
}

.mwb-blog-related-posts\_\_title a {  
font-size: {{ module.style.content\_styling.title\_font\_size.mobile.font\_size ~ ‘px’ }};  
line-height: {{ module.style.content\_styling.title\_font\_size.mobile.line\_height ~ ‘px’ }};  
}

.mwb-blog-related-posts\_\_author-detail span,  
.mwb-blog-related-posts\_\_author-detail a {  
font-size: {{ module.style.content\_styling.sub\_text\_font\_size.mobile.font\_size ~ ‘px’ }};  
line-height: {{ module.style.content\_styling.sub\_text\_font\_size.mobile.line\_height ~ ‘px’ }};  
}

{% endif %}

[@media](https://community.hubspot.com/t5/user/viewprofilepage/user-id/83477) only screen and (min-width: 768px) {  
.mwb-blog-related-posts\_\_card .mwb-blog-related-posts\_\_column,  
.mwb-blog-related-posts\_\_content-card .mwb-blog-related-posts\_\_column {  
margin-bottom: {{ module.style.posts\_bottom\_spacing.bottom\_spacing\_tablet\_ ~ ‘px’ }};  
}

{% if module.style.overwrite\_content\_styles %}

.mwb-blog-related-posts\_\_title a {  
font-size: {{ module.style.content\_styling.title\_font\_size.tablet.font\_size ~ ‘px’ }};  
line-height: {{ module.style.content\_styling.title\_font\_size.tablet.line\_height ~ ‘px’ }};  
}

.mwb-blog-related-posts\_\_author-detail span,  
.mwb-blog-related-posts\_\_author-detail a {  
font-size: {{ module.style.content\_styling.sub\_text\_font\_size.tablet.font\_size ~ ‘px’ }};  
line-height: {{ module.style.content\_styling.sub\_text\_font\_size.tablet.line\_height ~ ‘px’ }};  
}

{% endif %}

}

[@media](https://community.hubspot.com/t5/user/viewprofilepage/user-id/83477) only screen and (min-width: 992px) {  
.mwb-blog-related-posts\_\_card .mwb-blog-related-posts\_\_column,  
.mwb-blog-related-posts\_\_content-card .mwb-blog-related-posts\_\_column {  
margin-bottom: {{ module.style.posts\_bottom\_spacing.bottom\_spacing\_desktop\_ ~ ‘px’ }};  
}

{% if module.style.overwrite\_content\_styles %}

.mwb-blog-related-posts\_\_title a {  
font-size: {{ module.style.content\_styling.title\_font\_size.desktop.font\_size ~ ‘px’ }};  
line-height: {{ module.style.content\_styling.title\_font\_size.desktop.line\_height ~ ‘px’ }};  
}

.mwb-blog-related-posts\_\_author-detail span,  
.mwb-blog-related-posts\_\_author-detail a {  
font-size: {{ module.style.content\_styling.sub\_text\_font\_size.desktop.font\_size ~ ‘px’ }};  
line-height: {{ module.style.content\_styling.sub\_text\_font\_size.desktop.line\_height ~ ‘px’ }};  
}

{% endif %}

}

[@media](https://community.hubspot.com/t5/user/viewprofilepage/user-id/83477) only screen and (min-width: 1366px) {

.mwb-blog-related-posts\_\_compact .mwb-blog-related-posts\_\_column:not(:first-child) .mwb-blog-related-posts\_\_img img {  
height: 250px;  
object-fit: cover;  
}

.mwb-blog-related-posts\_\_compact .mwb-blog-related-posts\_\_column:first-child .mwb-blog-related-posts\_\_img img {  
height: 520px;  
object-fit: cover;  
}  
}

{% end\_scope\_css %}  
\</style\>  
{% end\_require\_css %}

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [February 28, 2023, 7:13pm UTC](https://community.hubspot.com/t/displaying-related-posts-problem/76127/2 "2023-02-28T19:13:25Z")

</div>

Hi, @MSaliba5 👋 Do you have any links to the pages that:

- work as expected?
- don’t work as expected?

Sometimes seeing the issue in action helps the community understand the issue.

Best,

Jaycee

---

<div class="post-metadata">

**Author:** ![jnix284](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jnix284/32/29_2.png) [@jnix284](https://community.hubspot.com/u/jnix284)\
**Post date:** [March 2, 2023, 2:51am UTC](https://community.hubspot.com/t/displaying-related-posts-problem/76127/3 "2023-03-02T02:51:15Z")

</div>

Hi @MSaliba5 the links [@Jaycee\_Lewis](https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074) requested would be helpful.

I didn’t read every line of code, but my guess is that however you have defined “related” is limiting the availability of articles on the posts that only have 2, whereas the posts with 3 have more blogs that meet the criteria.
