We use cookies to make HubSpot's community a better place. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. To learn more, and to see a full list of cookies we use, check out our Cookie Policy (baked goods not included).
Dec 2, 2022 1:20 AM - edited Dec 2, 2022 1:32 AM
I want to use the HubL function blog_recent_posts to display tags.
Is there any way to do this?
```
{% set rec_posts = blog_recent_posts(11111111111, 10) %}
{% for rec_post in rec_posts %}
<span class="category">{{rec_posts.tag }}</span>
{% endfor %}
```
Solved! Go to Solution.
Dec 2, 2022 5:00 AM
My bad! I misinterpreted your original request... So you want to do something like that to retrieve the tags:
{% set rec_posts = blog_recent_posts(11111111111, 10) %}
{% for rec_post in rec_posts %}
<div class="article">
<a class="list-link" href="{{rec_post.url}}">
{% for tag in rec_post.tag_list %}
<div class="category">{{ tag.name }}</div>
{% endfor %}
<div class="title">{{ rec_post.name }}</div>
</a>
</div>
{% endfor %}
Matthieu
matthieu.berard@markentive.com
Dec 2, 2022 4:01 AM
Hi @m_engineer ,
If you only want to display tags from a specific blog you should use the blog_tags function instead.
You can find details on the documentation here.
Here is a qucik resume on how you use it:
{% set my_tags = blog_tags(11111111111, 10) %}
<ul>
{% for item in my_tags %}
<li><a href="{{ blog_tag_url(group.id, item.slug) }}">{{ item }}</a></li>
{% endfor %}
</ul>
Hope it helps 😊
Matthieu
matthieu.berard@markentive.com
Dec 2, 2022 4:42 AM
Thank you for your response.
How can I retrieve new posts and display tag information from the retrieved posts?
Is it possible to use the blog_tags function?
{% set rec_posts = blog_recent_posts(11111111111, 10) %}
{% for rec_post in rec_posts %}
<div class="article">
<a class="list-link" href="{{rec_post.url}}">
<div class="category">{{ rec_post.tag }}</div>
<div class="title">{{ rec_post.name }}</div>
</a>
</div>
{% endfor %}
Dec 2, 2022 5:00 AM
My bad! I misinterpreted your original request... So you want to do something like that to retrieve the tags:
{% set rec_posts = blog_recent_posts(11111111111, 10) %}
{% for rec_post in rec_posts %}
<div class="article">
<a class="list-link" href="{{rec_post.url}}">
{% for tag in rec_post.tag_list %}
<div class="category">{{ tag.name }}</div>
{% endfor %}
<div class="title">{{ rec_post.name }}</div>
</a>
</div>
{% endfor %}
Matthieu
matthieu.berard@markentive.com
Dec 4, 2022 9:15 PM
This is exactly the answer I was looking for!
Thank you very much.