Display Recent Blog Post by Topic

New Contributor



We want to add in our home page recent blog post by topic . I have followed the documentation here in Hubspot. But still the desired output won't appear.


Wonder where did I got wrong


{{ blog_recent_topic_posts(6097481406, 'events-video', 3 ) }}
{% set topic_posts = blog_recent_topic_posts(6097481406, 'events-video', 3) %}
{% for topic_post in topic_posts %}

<div class="related-image">
{% if topic_post.featured_image %}
<a class="post-list-thumb" href="{{ topic_post.absolute_url }}">
 <img src="{{ topic_post.featured_image }}" alt="{{ topic_post.name }}">
{% endif %}
<div class="recent-right-col">
<a href="{{ topic_post.absolute_url }}">{{ topic_post.name }}</a>
 <div  class="custom-date">
{{ topic_post.publish_date_local_time.strftime('%d') }}
    {{ topic_post.publish_date_local_time.strftime('%B') }},
	{{ topic_post.publish_date_local_time.strftime('%Y') }}
{% endfor %}

1 Reply
HubSpot Moderator



The code provided above does appear correct but there are a couple suggestions I would provide that could help you troubleshoot this problem. I assume that when trying to use this module that you're not seeing anything appear on the page. I would double-check both the Blog ID and the topic name to make sure they are exactly as they appear in HubSpot. If the tag name if even a little off nothing will be returned from the above function. I would also try and pprint the object to the page just to make sure you have the data after you set it as a variable. Before you for loop I would try the following and make sure you're getting the correct data back from the HubL function. 


{{ topic_posts|pprint }}

If you see the data displaying on the page that is a good sign and I would do the same in the for loop but for topic_post and then make sure each of the objects you're trying to access from topic_post are avaible.