Tickets & Conversations

VladOnishchenko
Member

HubSpot related_blog_posts doesn't show all related posts, even with default post_formatter

Hello team!

 

We created Blog with a custom Blog Article template and several Blog posts.

 

In the Blog Article template we use related_blog_posts in this way

{% related_blog_posts, no_wrapper=True, limit=21 %}

with limit value more than default "3".

image.png

 

The count of the Blog posts is 10, but on the Article page we can see only 7 of them for some reason.

 

Could it be related to the pages settings somehow or something else? 

0 Upvotes
4 Replies 4
webdew
Guide | Diamond Partner
Guide | Diamond Partner

HubSpot related_blog_posts doesn't show all related posts, even with default post_formatter

Hi @VladOnishchenko ,

We have added the code for the Related blogs. Please add this code to your blog template and you can add this code to your custom module also. Now I have set the limit=21 if you want to edit just replace the values according to your need. Refer screenshot

https://prnt.sc/115hi5d

 

Note:- if you are displaying 21 blogs listing make sure the 21 blogs are available on your blogs.

 

 

<!--   Related blog listing-->

          {% macro recent_post(post, count, total) %}

{% if count == 1 %}

<section class="blog-related-posts">

  <h2 class="blog-related-posts__title">Related Articles</h2>

  <div class="blog-related-posts__list">

{% endif %}

<article class="related-post">

  {% if post.featured_image %}

    <div class="related-post__image-wrapper">

      <a href="{{ post.absolute_url }}">

        <img class="related-post__image" src="{{ post.featured_image }}" loading="lazy" alt="{{ post.featured_image_alt_text }}">

      </a>

    </div>

  {% endif %}

  <section class="related-post__content">

    {% if post.tag_list %}

      <div class="related-post__tags">

        {% for tag in post.tag_list %}

          <a class="related-post__tag-link" href="{{ blog_tag_url(group.id, tag.slug) }}">{{ tag.name }}</a>

        {% endfor %}

      </div>

    {% endif %}

    <h3 class="related-post__title"><a href="{{ post.absolute_url }}">{{ post.name }}</a></h3>

    <div class="related-post__post-summary">{{ post.post_list_content|truncatehtml(170) }}</div>

    <div class="related-post__author">

      {% if post.blog_author.avatar %}

        <div class="related-post__author-image-wrapper">

          <img class="related-post__author-image" src="{{ content.blog_author.avatar }}" width="45" loading="eager" alt="{{ content.blog_post_author.display_name }}">

        </div>

      {% endif %}

        <a class="related-post__author-name" href="{{ group.absolute_url }}/author/{{ post.blog_post_author.slug }}">{{ post.blog_post_author.display_name }}</a>

    </div>

    <a class="related-post__button button button" href="{{ post.absolute_url }}">Read More</a>

  </section>

</article>

{% if count == total %}

  </div>

</section>

{% endif %}

{% endmacro %}

 

{% related_blog_posts limit=21, post_formatter="recent_post", no_wrapper=True %}

<!--     code end       -->

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards. 

VladOnishchenko
Member

HubSpot related_blog_posts doesn't show all related posts, even with default post_formatter

Hello @webdew , hello team!

 

Many thanks for the quick responses and great solution! 

 

This solution is splendid! But only one thing we wanted to resolve.

There are the top 3  questions we struggle to understand...

 

1. So our scenario was - we had 10 blog posts and via calling this  {% related_blog_posts, no_wrapper=True, limit=21 %} we wanted to see exactly all 10 records on the page.

But we were getting only 7 of them for some reason..

So we wanted to know exactly what was the reason, some mistakes of using it from our side? Do we have any conclusion on this? 

 

2. If we just want to have 10 blog posts from 10 blog posts, then why we have to add some special formatters as {% related_blog_posts limit=21, post_formatter="recent_post", no_wrapper=True %}?
Does recent_post formatter make any trick on items count? As we know - it just helps to format the markup for each item in the collection..

 

3. Is it better to use limit=10 if we have 10 blog posts? And then, if we have 11 blog posts we need to change it to 11?

Ok, then what is the max value for limit, if we want to show for e.g. 100 or 200 blog posts or even more?  

 

Best regards,

 

VladOnishchneko

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

HubSpot related_blog_posts doesn't show all related posts, even with default post_formatter

Hey @VladOnishchenko 

 

1. The related blog post function scores blog posts on their relation to the current post/page. If a post is determined to have no relation, it won't be shown. That's why @webdew used recent instead because it will show all recent posts up to whatever limit is inputted.

2. The post_formatter can also be used in the related function. It is simply a way of telling the code how you want the posts to be visually shown on the page. Without a post formatter it would simply output plain text.

3. Yes, if you want just 10, set the limit to 10, but use recent instead of related else you possibly won't get the full 10 if they have no relation to the current post/page. I believe the limit for blog functions is 200 posts.

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.
0 Upvotes
PamCotton
Community Manager
Community Manager

HubSpot related_blog_posts doesn't show all related posts, even with default post_formatter

Hello @VladOnishchenko, I will add some top experts to share their thoughts, @Alex_@Gonzalo  what would you recommend to @VladOnishchenko matter?

 

Thank you,

Pam

Você sabia que a Comunidade está disponível em outros idiomas?
Participe de conversas regionais, alterando suas configurações de idioma !


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !