CMS Development

aniek_2
Member

Choose range of blog posts

SOLVE
Spoiler
I am creating an automated email for blog updates in which I want the newest blog post to stand out in the email. But to also bring under attention some other blog posts, I like to select the second and third latest blog post, and print them in the email as well, but with different styling, like this:
idea.PNG

My idea was to make two loops:
- 1 with the newest blog post:
{% set posts = blog_recent_posts('default', 1) %}
{% for post in posts%}

- another one with the second and third blog post:
{% set posts = blog_recent_posts('default', ??????) %}
{% for post in posts%}

But to be able to do this, I need to know how I can select the 2nd and 3rd post...

Anyone?

 

0 Upvotes
1 Accepted solution
louiegerodiaz
Solution
Contributor

Choose range of blog posts

SOLVE

Hello there!

 

Hope I'm not too late in answering this, but, you may use an index while looping through each blog post. Something like this:

{% set posts = blog_recent_posts('default', 5) %}
{% for post in posts%}
  {% if loop.index == 2 or loop.index == 3 %}
    <!-- some HTML elements -->
  {% endif %}
{% endfor %}

Let me know if this answers your question.

 

Cheers,

Louie

View solution in original post

0 Upvotes
3 Replies 3
louiegerodiaz
Solution
Contributor

Choose range of blog posts

SOLVE

Hello there!

 

Hope I'm not too late in answering this, but, you may use an index while looping through each blog post. Something like this:

{% set posts = blog_recent_posts('default', 5) %}
{% for post in posts%}
  {% if loop.index == 2 or loop.index == 3 %}
    <!-- some HTML elements -->
  {% endif %}
{% endfor %}

Let me know if this answers your question.

 

Cheers,

Louie

0 Upvotes
aniek_2
Member

Choose range of blog posts

SOLVE

Thank you for taking time to respond.

It works!

 

0 Upvotes
louiegerodiaz
Contributor

Choose range of blog posts

SOLVE

No problem! Glad I could help. Smiley Happy

0 Upvotes