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).
Oct 8, 2021 1:52 PM
Hi,
I created a recent posts module for the bottom of my blog to pull in the three most recent posts from the same topic as the present post. I like the way it's working, but... the first post is the current post.
So is there a way to add in an offset to take posts #2, #3 and #4 and/or exlcude the current post?
Here's the gist of the module:
{% set number_of_posts = 3 %}
{% set posts = blog_recent_topic_posts("default", content.topic_list[0].slug, 3) %}
{% if module.specific_tag_topic %}
{% set posts = blog_recent_topic_posts(module.choose_blog, module.tag, number_of_posts) %}
{% endif %}
<section class="blog-feed">
<div>
<h2>
Related Reading
</h2>
</div>
<div class="blog-posts">
{% for post in posts %}
<div class="blog-post">
<div class="ni-post blog-post-inner">
<div class="blog-post-image" style="background-image: url({{ resize_image_url( post.featured_image,0,350 ) }});"></div>
<div class="blog-post-content-wrapper">
<a class="blog-post-title" href="{{ post.absolute_url }}"><h3>{{ post.name }}</h3></a>
<a class="blog-post-read-more" href="{{ post.absolute_url }}">Read More →</a>
</div>
</div>
</div>
{% endfor %}
</div>
</section>
Solved! Go to Solution.
Oct 10, 2021 3:02 AM
Similar to what @Teun said but instead of doing content.name you do a range. Below should work.
{% set number_of_posts = 3 %}
{% set posts = blog_recent_topic_posts("default", content.topic_list[0].slug, 4) %}
{% if module.specific_tag_topic %}
{% set posts = blog_recent_topic_posts(module.choose_blog, module.tag, number_of_posts) %}
{% endif %}
<section class="blog-feed">
<div>
<h2>
Related Reading
</h2><br>
</div>
<div class="blog-posts">
{% for post in posts %}
{% if loop.index in range(2,99) %}
<div class="blog-post">
<div class="ni-post blog-post-inner">
<div class="blog-post-image" style="background-image: url({{ resize_image_url( post.featured_image,0,350 ) }});"></div>
<div class="blog-post-content-wrapper">
<a class="blog-post-title" href="{{ post.absolute_url }}"><h3>{{ post.name }}</h3></a>
<a class="blog-post-read-more" href="{{ post.absolute_url }}">Read More →</a>
</div>
</div>
</div>
{% endif %}
{% endfor %}
</div>
</section>
Oct 10, 2021 3:02 AM
Similar to what @Teun said but instead of doing content.name you do a range. Below should work.
{% set number_of_posts = 3 %}
{% set posts = blog_recent_topic_posts("default", content.topic_list[0].slug, 4) %}
{% if module.specific_tag_topic %}
{% set posts = blog_recent_topic_posts(module.choose_blog, module.tag, number_of_posts) %}
{% endif %}
<section class="blog-feed">
<div>
<h2>
Related Reading
</h2><br>
</div>
<div class="blog-posts">
{% for post in posts %}
{% if loop.index in range(2,99) %}
<div class="blog-post">
<div class="ni-post blog-post-inner">
<div class="blog-post-image" style="background-image: url({{ resize_image_url( post.featured_image,0,350 ) }});"></div>
<div class="blog-post-content-wrapper">
<a class="blog-post-title" href="{{ post.absolute_url }}"><h3>{{ post.name }}</h3></a>
<a class="blog-post-read-more" href="{{ post.absolute_url }}">Read More →</a>
</div>
</div>
</div>
{% endif %}
{% endfor %}
</div>
</section>
Oct 9, 2021 4:00 AM