- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Related Post Loop
07-02-2019 05:08
Hello Hubspot Devs !!!!
It seems that my problems always revolve around blog loops. So I have this related blog loop :
{% if content.topic_list %} {% for topic in content.topic_list %} {% if loop.first %} {% set related_posts = blog_recent_topic_posts(module.blog_id, topic.slug, 2) %} {% for post in related_posts %} {% unless content.absolute_url == post.absolute_url %} <div>My Markup like : <h3><a href="{{ post.absolute_url }}">{{ post.name }}</a></h3> </div> {% endunless %} {% endfor %} {% endif %} {% endfor %} {% endif %}
The idea is to get only two suggestions for the current article.
I use the "unless" loop to remove the current article from the suggestions.
With this setup I only get 1 or none article suggestion. If I increase the suggestion count to 3, I get two suggestions, but sometimes 3 (which is not the goal).
I tried to get more articles something like :
{% set related_posts = blog_recent_topic_posts(module.blog_id, topic.slug, 10) %} {% for post in related_posts %} {% if loop.index <= 2 %} Again my markup {% endif %} {% endfor %}
It doesn't work at all. I suspect I only get one article because of the "unless" condition. The thing is that if I remove the "unless" I get the current article in suggestion wich defies the purpose of a related articles block.
Any help will be kindly appreciated.
Kind regards,
Theodor
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content