CMS Development

TCorrêadeSous
Member

Do not show duplicate blog posts

I have two sections on the blog's homepage, one with the highlights of the last 3 posts made, and another with the other posts, being shown every 6 posts.

I managed to remove the last three posts made from this second section, so they wouldn't be repeated. The problem is that it pulls out 3 posts on every page. I tried to create an IF using the home url, but when I test the condition in the console it gives true, when I try to apply it in this code, it only runs the ELSE.


Blog link: https://blog.netlex.io/
(in this section of more news I had to show 6 posts)


my code:

<section class="blog-index">
    <div class="page-title">
        <h1 class="sub" id="moreNewsTitle">
        {% if topic %}
            {{ topic }} 
        {% else %}
            Mais notícias
        {% endif %}</h1>
        <div class="line-orange"></div>
    </div>
    <div class="articles">
        {% if (!contents) %}
            <h1 class="no-article-message">There is nothing here yet</h1>
        {% endif %}
        {% if window.location.href.toString() == 'https://7986429.hs-sites.com/pt-br/company-blog-testes' %}
            {% for content in contents %}
                {% if loop.index >= 4 %}
                    <a class="article" href="{{ content.absolute_url }}">
                        <div class="article-image-parent">
                            <div class="article-img" style="background-image: url('{{ content.featured_image }}');"></div>
                        </div>
                        <div class="tags">
                            {% for tag in content.tag_list %}
                              {% if loop.index <= 3 %}
                                  <div class="tag" href="{{ blog_tag_url(group.id, tag.slug) }}">
                                  {{ tag.name }}
                                  </div>
                              {% endif %}
                            {% endfor %}
                        </div>
                        <script>console.log('testePost')</script>
                        {# Title #}

                        {% if module.title %}
                            <h3>{{ content.name }}</h3>
                        {% endif %}

                        {% if module.description %}
                            {{ content.post_list_content|truncatehtml(100) }}
                        {% endif %}

                        <div class="card-footer">
                            <div class="article-info">
                                <h4>{{ content.blog_post_author.display_name }}</h4>
                                <h5>{{ content.publish_date|datetimeformat('%d/%m/%y') }} | </h5>
                                <h5 id="postTimeNumber"></h5> <h5 class="article-info-time"></h5>
                            </div>
                        </div>
                    </a>
                {% endif %}
            {% endfor %}
        {% else %}
            {% for content in contents %}
                <a class="article" href="{{ content.absolute_url }}">
                    <div class="article-image-parent">
                        <div class="article-img" style="background-image: url('{{ content.featured_image }}');"></div>
                    </div>
                    <div class="tags">
                        {% for tag in content.tag_list %}
                        {% if loop.index <= 3 %}
                            <div class="tag" href="{{ blog_tag_url(group.id, tag.slug) }}">
                            {{ tag.name }}
                            </div>
                        {% endif %}
                        {% endfor %}
                    </div>
                    <script>console.log('testePost2')</script>
                    {# Title #}

                    {% if module.title %}
                        <h3>{{ content.name }}</h3>
                    {% endif %}

                    {% if module.description %}
                        {{ content.post_list_content|truncatehtml(100) }}
                    {% endif %}

                    <div class="card-footer">
                        <div class="article-info">
                            <h4>{{ content.blog_post_author.display_name }}</h4>
                            <h5>{{ content.publish_date|datetimeformat('%d/%m/%y') }} | </h5>
                            <h5 id="postTimeNumber"></h5> <h5 class="article-info-time"></h5>
                        </div>
                    </div>
                </a>
            {% endfor %}
        {% endif %}
    </div>
</section>
0 Upvotes
2 Replies 2
Sjardo
Top Contributor | Elite Partner
Top Contributor | Elite Partner

Do not show duplicate blog posts

Hi,

 

I do not have an piece example code, but my first thoughts are collecting the post ID's that you want to show, put them in an array certain array for each section, make sure it only contains unique values and check them agaisnt an other array for duplicate ID's.

 

After that, get the blog content by ID.

0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

Do not show duplicate blog posts

Hi, @TCorrêadeSous 👋 Let's see if we can get this conversation going for you. 

 

@Sjardo @piersg @Jnix284, do you have any insight for @TCorrêadeSous and their issue? 

 

Thanks! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes