CMS Development

Emeline_Impala
Participant | Elite Partner
Participant | Elite Partner

Related posts showing up quite "randomly"

Hi there,

 

We're having an issue with the related posts' default functions.

 

Related posts from the same topic should show up with a limit of 3 posts, but it's currently not the case: related posts that are showing are not always from the same topic as the current post, and we sometimes got only 1 or 2 posts populated while there are more than 3 posts published within the topic.

 

Any idea? Does anyone else experience this problem?

 

Here is our current code:

<div class="b-mostRead">
        <h2 class="b-mostRead__title">
            {{ module.read_more || 'Voir aussi' }}
        </h2>
        <div>{% set tags = content.topic_list|join(', ') %}</div>
        <div class="b-list">
            {% macro blog_post_formatter(blog_post, index, count) %}
            <article class="article">
                <a class="article-image-bg _hrl" href="{{ blog_post.absolute_url }}" style="background-image: url('{{ blog_post.featured_image | replace('hubfs/'~ hub_id, 'hub/' ~ hub_id ~ '/hubfs') }}?height=214');"></a>
                <!--
                <a class=" article-image _hrl" href="{{ blog_post.absolute_url }}">
                    <img src="{{ blog_post.featured_image }}" alt="{{ blog_post.title }}">
                </a>
                -->
                <div class="article-content">
                    <h2 class="article-title" style="height: 59px;">
                        <a href="{{ blog_post.absolute_url }}">{{ blog_post.title }}</a>
                    </h2>
                    <p class="article-author">
                        <span class="circle"></span>
                        <span class="text">{{ blog_post.blog_post_author.display_name }} </span>
                    </p>
                </div>
            </article>
            {% endmacro %}
            {% related_blog_posts limit=3, post_formatter="blog_post_formatter", tags="{{ tags }}" %}
        </div>
    </div>

Thanks for your help!

0 Upvotes
1 Reply 1
John
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Related posts showing up quite "randomly"

it is your {{ tags }} statement. If you print {{ tags }} it will probably be blank. You need to replace that statement with a string.

{% related_blog_posts limit=3, post_formatter="blog_post_formatter", tags="{{ tags }}" %}
{% set tag_string = content.topic_list|join(',') %}
{% related_blog_posts limit=3, post_formatter="blog_post_formatter", tags="{{ tag_string }}" %}


I like kudos almost as much as cake – a close second.