Dec 30, 2020 5:39 PM - edited Jan 11, 2021 12:50 PM
Hi, when coding my blog template I'm wondering what's the best way to return 5 blog posts, then a regular text block, followed by the next 5 post in chronological order?
Basically I'm pulling in 10 posts in the top half but using "display:none" to hide posts 6, 7, 8, 9, 10. After that, I have the the text block "Let us help you do more", followed by another set of 10 blog posts but hiding posts 1, 2, 3, 4, 5 this time.
This way seems a bit "hacky" and not great for accessibility so if anyone can think of alternative ways to accomplish this that would be much appreciated. Thanks!
Solved! Go to Solution.
Dec 31, 2020 6:06 PM - edited Mar 1, 2021 8:24 PM
If you want to add a text block, just choose the index of your loop and add an if statement. You may need to change the 10 you're pulling in to 11.
{% if loop.index == 6 %}
ADD YOUR TEXT BLOCK
{% endif %}
Joshua Todd | CEO of Pixl Labs
Dec 31, 2020 6:06 PM - edited Mar 1, 2021 8:24 PM
If you want to add a text block, just choose the index of your loop and add an if statement. You may need to change the 10 you're pulling in to 11.
{% if loop.index == 6 %}
ADD YOUR TEXT BLOCK
{% endif %}
Joshua Todd | CEO of Pixl Labs
Jan 5, 2021 7:19 PM - edited Jan 5, 2021 7:20 PM
Hi @josh_dev, appreciate the reply that's exactly what I was looking for.
Now if I wanted to pull my text block (below) into the code to add in that loop, how would I go about doing that? Basically I need this text block to be editable for the content team but it needs to be inserted in the code at that 6th spot in the loop. Thanks!
Jan 5, 2021 11:07 PM - edited Mar 1, 2021 8:23 PM
I'd recommend creating a custom module for them instead.
Make the text block into fields on the module.
https://developers.hubspot.com/docs/cms/building-blocks/modules
Hope that helps!
Joshua Todd | CEO of Pixl Labs
👉www.pixllabs.io