Creating a custom blog listing

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!

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 %}

Thanks @erod but I actually need to split the artticles in to three sections:

  • Article 1 - ‘Feature Pick’ tagged Post.
  • Articles 2,3,4 - 3 Next most recent articles.
  • CTA (and other bits and pieces)
  • All other Articles .

Is there a way of doing that with your solution above?

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 %}

Hi @DM2 ,
You can use this Hubspot blog listing module and create the blog listing customization according to your need. Edit blog listing pages

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.
Thanks and Regards.

Thanks @webdew but unfortunately that doesn’t help my particular scenario.

I feel like @Anton just had an answer for this recently. @Anton , remember what post that was?

Hello @DM2 ,

You can utilize this Hubspot blog posting module and

make

the blog posting customization as per your need. Edit blog listing pages

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.

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 %}

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