Filter one topic in a multiple blog listing

SOLVE
Highlighted
Regular Contributor

I am combining 4 blogs and would like to only show 3 total posts with one topic. 

 

{% set blog_one_posts = blog_recent_posts('XXXXXXXXXX', limit=3, tags="Marketing Tips") %} <!-- video --> 
{% set blog_two_posts = blog_recent_posts('XXXXXXXXXX', limit=3, tags="Marketing Tips") %} <!-- article -->
{% set blog_three_posts = blog_recent_posts('XXXXXXXXXX', limit=3, tags="Marketing Tips") %} <!-- infographic -->
{% set blog_four_posts = blog_recent_posts('XXXXXXXXXX', limit=3, tags="Marketing Tips") %} <!-- report -->

{% set all_posts = (blog_one_posts + blog_two_posts + blog_three_posts + blog_four_posts) | sort(true, false, 'publish_date')  %} 
{% for post in all_posts %}
content here
{% endfor %}

 

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
Solution
Regular Contributor

This worked:

{% set blog_one_posts = blog_recent_topic_posts('XXXXXXXXXX', 'marketing-tips', 3) %} <!-- video --> 
{% set blog_two_posts = blog_recent_topic_posts('XXXXXXXXXX', 'marketing-tips', 3) %} <!-- article -->
{% set blog_three_posts = blog_recent_topic_posts('XXXXXXXXXX', 'marketing-tips', 3) %} <!-- infographic -->
{% set blog_four_posts = blog_recent_topic_posts('XXXXXXXXXX', 'marketing-tips', 3) %} <!-- report -->

{% set all_posts = (blog_one_posts + blog_two_posts + blog_three_posts + blog_four_posts) | sort(true, false, 'publish_date')  %} 

And

{% for post in all_posts %}
content here
{% endfor %}

:

View solution in original post

Reply
0 Upvotes
5 Replies 5
Highlighted
Regular Contributor

I also tried different syntax

 

{% set blog_one_posts = blog_recent_posts('XXXXXXXXXX', marketing-tips, 3) %}
{% set blog_one_posts = blog_recent_posts('XXXXXXXXXX', 'marketing-tips', 3) %}
{% set blog_one_posts = blog_recent_posts('XXXXXXXXXX', 'Marketing Tips', 3) %}

 

 

Reply
0 Upvotes
Highlighted
Community Manager

@sking1

add this to your for loop

{% for post in all_posts %}
  {% if loop.index < 4 %} 
     content here
  {% endif %}
{% endfor %}
Thanks,

Dennis


We are excited to announce that the Community will be launching a weekly newsletter on November 2, 2020!
Sign up today!
Reply
0 Upvotes
Highlighted
Solution
Regular Contributor

This worked:

{% set blog_one_posts = blog_recent_topic_posts('XXXXXXXXXX', 'marketing-tips', 3) %} <!-- video --> 
{% set blog_two_posts = blog_recent_topic_posts('XXXXXXXXXX', 'marketing-tips', 3) %} <!-- article -->
{% set blog_three_posts = blog_recent_topic_posts('XXXXXXXXXX', 'marketing-tips', 3) %} <!-- infographic -->
{% set blog_four_posts = blog_recent_topic_posts('XXXXXXXXXX', 'marketing-tips', 3) %} <!-- report -->

{% set all_posts = (blog_one_posts + blog_two_posts + blog_three_posts + blog_four_posts) | sort(true, false, 'publish_date')  %} 

And

{% for post in all_posts %}
content here
{% endfor %}

:

View solution in original post

Reply
0 Upvotes
Highlighted
Community Manager

@sking1, that will not limit to 3.  you are limiting each of the individual blogs to 3, but collectively, you will get 12.  

Thanks,

Dennis


We are excited to announce that the Community will be launching a weekly newsletter on November 2, 2020!
Sign up today!
Reply
0 Upvotes
Highlighted
Regular Contributor

Yes, thank you. I have a loop inside, that part I didn't need help on.