CMS Development

sking1
Contributor

Filter one topic in a multiple blog listing

SOLVE

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

 

0 Upvotes
1 Accepted solution
sking1
Solution
Contributor

Filter one topic in a multiple blog listing

SOLVE

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

0 Upvotes
5 Replies 5
dennisedson
HubSpot Product Team
HubSpot Product Team

Filter one topic in a multiple blog listing

SOLVE

@sking1

add this to your for loop

{% for post in all_posts %}
  {% if loop.index < 4 %} 
     content here
  {% endif %}
{% endfor %}
0 Upvotes
sking1
Solution
Contributor

Filter one topic in a multiple blog listing

SOLVE

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

:

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Filter one topic in a multiple blog listing

SOLVE

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

0 Upvotes
sking1
Contributor

Filter one topic in a multiple blog listing

SOLVE

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

sking1
Contributor

Filter one topic in a multiple blog listing

SOLVE

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

 

 

0 Upvotes