# Related articule

**URL:** <https://community.hubspot.com/t/related-articule/28588>\
**Category:** CMS Development\
**Created:** [December 1, 2020, 11:19am UTC](https://community.hubspot.com/t/related-articule/28588 "2020-12-01T11:19:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lourdes14](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lourdes14/32/18373_2.png) [@Lourdes14](https://community.hubspot.com/u/Lourdes14)\
**Post date:** [December 1, 2020, 11:19am UTC](https://community.hubspot.com/t/related-articule/28588/1 "2020-12-01T11:19:16Z")

</div>

Hello! Under my posts i have the section about related articules, but they seem to be random and i want to have a relation between the main post and the related post. I dont know if it is posibble to relate them by tag or topic.

Now i have this code:

\<div class=“recent-posts”\>  
{% if content.topic\_list %}  
{% for topic in content.topic\_list %}  
{% if loop.first %}  
{% set counter = 0 %}  
{% set related\_posts = blog\_recent\_topic\_posts(‘default’, topic.slug, 4 ) %}  
{% for post in related\_posts %}  
{% unless content.absolute\_url == post.absolute\_url %}  
{% set counter = counter + 1 %}  
{% if counter \< 4 %}  
\<div class=“recent-post”\>  
\<a href=“{{ post.absolute\_url }}”\>  
\<div class=“recent-post-featured-image” style=“background-image: url(‘{{ post.featured\_image }}’)”\>\</div\>  
\</a\>  
\<div class=“recent-post-content”\>  
\<p class=“recent-post-info”\>  
\<i style=“color:#1883b3;” class=“fa fa-calendar”\>\</i\>  
{{ post.publish\_date|datetimeformat(‘%d %B, %Y’) }} \&nbsp;\&nbsp;\&nbsp;  
\<i class=“fa fa-tags” style=“color:#1883b3;”\>\</i\>  
\<a class=“topic-related” href=“{{ group.absolute\_url }}/topic/{{ content.topic\_list[0].slug }}”\>  
{{post.topic\_list[0].name }}  
\</a\>  
\</p\>  
\<a href=“{{ post.absolute\_url }}”\>  
\<h4 class=“recent-post-title”\>{{ post.name }}\</h4\>  
\<p class=“recent-post-read-more hs-button primary” href=“{{ post.absolute\_url }}”\>Seguir leyendo\</p\>  
\</a\>  
\</div\>  
\</div\>  
{% endif %}  
{% endunless %}  
{% endfor %}  
{% endif %}  
{% endfor %}  
{% endif %}  
\</div\>

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [December 1, 2020, 5:23pm UTC](https://community.hubspot.com/t/related-articule/28588/2 "2020-12-01T17:23:08Z")

</div>

Hi @Lourdes14, here’s my HubL for getting recent posts with the same tag/topic as the blog article being read (not including the one being read):

```lia-code-sample
{% set rec_posts = blog_recent_tag_posts('default',content.tag_list[0].slug, 4) %}
{% set loop = 0 %}
{% for rec_post in rec_posts %}
 {% unless rec_post.id == content.id %}
 {% set loop = loop + 1 %}
 {% if loop < 3 %}
 // recent/similar post code here

 {% endif %}
 {% endunless %}
{% endfor %}

```

---

<div class="post-metadata">

**Author:** ![Lourdes14](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lourdes14/32/18373_2.png) [@Lourdes14](https://community.hubspot.com/u/Lourdes14)\
**Post date:** [December 2, 2020, 9:48am UTC](https://community.hubspot.com/t/related-articule/28588/3 "2020-12-02T09:48:48Z")

</div>

Hi @piersg!! Thanks for your help but it still does not work, I have tried to replace with the piece of code that you have passed me but it still does not work, could you modify the code of this comment with the code that you tell me to see if I am doing something wrong? Thanks for your time 🙂

{# Posts relacionados (Old) #}  
\<h3 class=“title-comment”\>Posts relacionados\</h3\>  
\<div class=“recent-posts”\>  
{% if content.topic\_list %}  
{% for topic in content.topic\_list %}  
{% if loop.first %}  
{% set counter = 0 %}  
{% set related\_posts = blog\_recent\_topic\_posts(‘default’, topic.slug, 4 ) %}  
{% for post in related\_posts %}  
{% unless content.absolute\_url == post.absolute\_url %}  
{% set counter = counter + 1 %}  
{% if counter \< 4 %}  
\<div class=“recent-post”\>  
\<a href=“{{ post.absolute\_url }}”\>  
\<div class=“recent-post-featured-image” style=“background-image: url(‘{{ post.featured\_image }}’)”\>\</div\>  
\</a\>  
\<div class=“recent-post-content”\>  
\<p class=“recent-post-info”\>  
\<i style=“color:#1883b3;” class=“fa fa-calendar”\>\</i\>  
{{ post.publish\_date|datetimeformat(‘%d %B, %Y’) }} \ \ \   
\<i class=“fa fa-tags” style=“color:#1883b3;”\>\</i\>  
\<a class=“topic-related” href=“{{ group.absolute\_url }}/topic/{{ content.topic\_list[0].slug }}”\>  
{{post.topic\_list[0].name }}  
\</a\>  
\</p\>  
\<a href=“{{ post.absolute\_url }}”\>  
\<h4 class=“recent-post-title”\>{{ post.name }}\</h4\>  
\<p class=“recent-post-read-more hs-button primary” href=“{{ post.absolute\_url }}”\>Seguir leyendo\</p\>  
\</a\>  
\</div\>  
\</div\>  
{% endif %}  
{% endunless %}  
{% endfor %}  
{% endif %}  
{% endfor %}  
{% endif %}  
\</div\>

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [December 2, 2020, 10:11am UTC](https://community.hubspot.com/t/related-articule/28588/4 "2020-12-02T10:11:33Z")

</div>

Sure

```lia-code-sample
{# Posts relacionados (Old) #}
<h3 class="title-comment">Posts relacionados</h3>
<div class="recent-posts">
 {% set rec_posts = blog_recent_tag_posts('default',content.tag_list[0].slug, 4) %}
 {% set loop = 0 %}
 {% for post in rec_posts %}
 {% unless post.id == content.id %}
 {% set loop = loop + 1 %}
 {% if loop < 4 %}
 <div class="recent-post">
 <a href="{{ post.absolute_url }}">
 <div class="recent-post-featured-image" style="background-image: url('{{ post.featured_image }}')"></div>
 </a>
 <div class="recent-post-content">
 <p class="recent-post-info">
 <i style="color:#1883b3;" class="fa fa-calendar"></i>
 {{ post.publish_date|datetimeformat('%d %B, %Y') }}    
 <i class="fa fa-tags" style="color:#1883b3;"></i>
 <a class="topic-related" href="{{ group.absolute_url }}/topic/{{ content.topic_list[0].slug }}">
 {{post.topic_list[0].name }}
 </a>
 </p>
 <a href="{{ post.absolute_url }}">
 <h4 class="recent-post-title">{{ post.name }}</h4>
 <p class="recent-post-read-more hs-button primary" href="{{ post.absolute_url }}">Seguir leyendo</p>
 </a>
 </div>
 </div>
 {% endif %}
 {% endunless %}
 {% endfor %}
</div>

```
