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 7, 2021 5:26 AM
hi there
I want to create a blog listing that goes like this (row by row):
Article 1 - 'Feature Pick' tagged Post.
Articles 2,3,4 - 3 Next most recent articles.
CTA.
All other Articles .
I am nearly there using this:
{% set rec_posts = blog_recent_posts('default', 99) %}
{% for post in rec_posts %}
{% if 'Editors Pick' in post.topic_list|map('name') %}
// Article 1 - 'Feature Pick' tagged Post
{% endif %}
{% endfor %}
{% for post in rec_posts %}
{% if loop.index in range(1,4) %}
{% if 'Editors Pick' not in post.topic_list|map('name') %}
// Articles 2,3,4 - Next most recent articles
{% endif %}
{% endif %}
{% endfor %}
CTA.
{% for post in rec_posts %}
{% if loop.index in range(4,99) %}
{% if 'Editors Pick' not in post.topic_list|map('name') %}
// All other Articles
{% endif %}
{% endif %}
{% endfor %}
But am finding that becuase my 'Feature Pick' is techincally within the range (1,4) I am only getting 2 articles on that row. I could adjust it to range(1,5) but as soon as the article becomes older that system will break.
I am sure there is a better way of doing this if anyone could help I would be grateful.
Thank you!
Solved! Go to Solution.
Oct 8, 2021 1:42 PM
Try something like this. Be sure to set the range and don't forget that tags are case sensitive.
{# First loop: featured posts #}
{% for content in contents %}
{% for topic in content.topic_list %}
{% if topic.name == 'Featured' %}
{# Add your featured post markup here #}
{% endif %}
{% endfor %}
{% endfor %}
{# CTA GOES HERE #}
{% for content in contents %}
{% if loop.index in range(X,X) %}
{% for topic in content.topic_list %}
{% if topic.name != 'Featured' %}
{# Add your featured post markup here #}
{% endif %}
{% endfor %}
{% endfor %}
{# The rest of the posts #}
{% for content in contents %}
{% if loop.index in range(X,99) %}
{% for topic in content.topic_list %}
{% if topic.name != 'Featured' %}
{# Add your markup here #}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
Oct 11, 2021 7:59 AM
Thank you for your continued support @erod. I guess this comes down to whether, in the statement below, a 'Featured' article would be included within the count of a loop.index range even though we're not displaying it. I want to make sure I return 3 articles at this point. If the article is included I would only return 2?
{% for content in contents %}
{% if loop.index in range(1,4) %}
{% for topic in content.topic_list %}
{% if topic.name != 'Featured' %}
{# Add your featured post markup here #}
{% endif %}
{% endfor %}
{% endfor %}
Oct 11, 2021 3:55 PM
I tested it and it works. All you have to do is play around with the ranges. So, instead of 1,4 you might try 2,5 and then 6,99 for the rest. @DM2
Oct 11, 2021 7:17 AM - edited Oct 11, 2021 7:17 AM
Hello @DM2 ,
You can utilize this Hubspot blog posting module and make the blog posting customization as per your need. https://knowledge.hubspot.com/cos-blog/how-do-i-list-my-most-popular-posts-on-my-blog
Trust this makes a difference!
In case we had the option to answer your inquiry, compassionately help the local area by checking it as an answer.
Much obliged and Regards.
Oct 8, 2021 10:40 AM
Oct 8, 2021 9:17 AM
Thanks @webdew but unfortunately that doesn't help my particular scenario.
Oct 8, 2021 9:05 AM
Hi @DM2 ,
You can use this Hubspot blog listing module and create the blog listing customization according to your need. https://knowledge.hubspot.com/cos-blog/how-do-i-list-my-most-popular-posts-on-my-blog
Hope this helps!
If we were able to answer your query, kindly help the community by marking it as a solution.
Thanks and Regards.
Oct 7, 2021 1:27 PM
Hi DM2,
You need to do something like this:
{# First loop: featured posts #}
{% for content in contents %}
{% for topic in content.topic_list %}
{% if topic.name == 'featured' %}
{# Add your featured post markup here #}
{% endif %}
{% endfor %}
{% endfor %}
{# Second loop: all other posts #}
{% for content in contents %}
{% for topic in content.topic_list %}
{% if topic.name != 'featured' %}
{# Add the markup for the rest of your posts here #}
{% endif %}
{% endfor %}
{% endfor %}
Oct 8, 2021 3:39 AM - edited Oct 8, 2021 3:42 AM
Thanks @erod but I actually need to split the artticles in to three sections:
Is there a way of doing that with your solution above?
Oct 8, 2021 1:42 PM
Try something like this. Be sure to set the range and don't forget that tags are case sensitive.
{# First loop: featured posts #}
{% for content in contents %}
{% for topic in content.topic_list %}
{% if topic.name == 'Featured' %}
{# Add your featured post markup here #}
{% endif %}
{% endfor %}
{% endfor %}
{# CTA GOES HERE #}
{% for content in contents %}
{% if loop.index in range(X,X) %}
{% for topic in content.topic_list %}
{% if topic.name != 'Featured' %}
{# Add your featured post markup here #}
{% endif %}
{% endfor %}
{% endfor %}
{# The rest of the posts #}
{% for content in contents %}
{% if loop.index in range(X,99) %}
{% for topic in content.topic_list %}
{% if topic.name != 'Featured' %}
{# Add your markup here #}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}