CMS Development

Woodsy
Top Contributor

Combining multiple blogs

SOLVE

Hi I would like to combine two blogs that we have into a single list which displays the most recent first. I would like to set how many are displayed and have pagination similar to what is currently there. The two blogs are currently being controlled via the Settings > website > blogs options in Hubspot as this allows me to control how many are shown etc...


The two blog pages that currently exist are https://www.webinfinity.com/blog and https://www.webinfinity.com/newsI would like them both two appear under a single url https://www.webinfinity.com/blog.

 

I would then like the option to filter with a dropdown between the blogs and news.


I'm hoping that it will be easy enough to also change what is shown in the rightbar so that both blogs are included.


Thank you in advance for any help.

 

The code for the main listing is:

 

<div class="blog-section">
<div class="blog-listing-wrapper cell-wrapper">
{# simple_list_page indicates the "blog/all" page, which is a list of links to every blog post #}
<div class="post-listing{% if simple_list_page %}-simple{% endif %}">
{% if blog_author %}
<div class="hs-author-profile">
<h2 class="hs-author-name">{{ blog_author.display_name }}</h2>
{% if blog_author.avatar %} <div class="hs-author-avatar"> <img width="35 px" src="{{ blog_author.avatar }}" loading="lazy" alt="{{ blog_author.display_name }}"> </div> {% endif %}
<div class="hs-author-bio">{{ blog_author.bio }}</div>
{% if blog_author.has_social_profiles %}
<div class="hs-author-social-section">
<span class="hs-author-social-label">Find me on:</span>
<div class="hs-author-social-links">
{% if blog_author.facebook %}
<a href="{{ blog_author.facebook }}" target="_blank" class="hs-author-social-link hs-social-facebook fa fa-facebook"><span class="hs-screen-reader-text">Facebook</span></a>
{% endif %}
{% if blog_author.linkedin %}
<a href="{{ blog_author.linkedin }}" target="_blank" class="hs-author-social-link hs-social-linkedin fa fa-linkedin-square"><span class="hs-screen-reader-text">Linkedin</span></a>
{% endif %}
{% if blog_author.twitter %}
<a href="{{ blog_author.twitter }}" target="_blank" class="hs-author-social-link hs-social-twitter fa fa-twitter-square"><span class="hs-screen-reader-text">Twitter</span></a>
{% endif %}
{% if blog_author.google_plus %}
<a href="{{ blog_author.google_plus }}?rel=author" target="_blank" class="hs-author-social-link hs-social-google-plus fa fa-google-plus-square"><span class="hs-screen-reader-text">Google Plus</span></a>
{% endif %}
</div>
</div>
{% endif %}
</div>
<br />
<h2 class="hs-author-listing-header">Recent Posts</h2>
{% endif %}
{% for content in contents %}
<div class="post-item">
{% if not simple_list_page %}
{% if content.post_list_summary_featured_image %}
<div class="hs-featured-image-wrapper">
<a href="{{content.absolute_url}}" title="" class="hs-featured-image-link">
<img src="{{ content.post_list_summary_featured_image }}" loading="lazy" class="hs-featured-image" alt="{{ content.featured_image_alt_text }}">
</a>
</div>
{% endif %}
<div class="post-header clearfix">
<h2><a href="{{content.absolute_url}}">{{ content.name }}</a></h2>
<p id="hubspot-author_data" class="hubspot-editable" data-hubspot-form-id="author_data" data-hubspot-name="Blog Author"><span class="fa fa-calendar"></span>
{{ content.publish_date_localized }} / by
{%if content.blog_post_author %}
<a class="author-link" href="{{ group.absolute_url }}/author/{{ content.blog_post_author.slug }}">{{ content.blog_post_author.display_name }}</a>
{% endif %}
{% if content.topic_list %}
posted in
{% for topic in content.topic_list %}
<a class="topic-link" href="{{ group.absolute_url }}/topic/{{ topic.slug }}">{{ topic.name }}</a>{% if not loop.last %},{% endif %}
{% endfor %}
{% endif %}

<!--comments-->
<span class="custom_listing_comments"><span class="fa fa-comment"></span>
<a href="{{content.absolute_url}}#comments-listing">
{% set comments_number = content.comment_list|length %}
{% if comments_number == 1 %}
{% set comments_label = "Comment" %}
{% else %}
{% set comments_label = "Comments" %}
{% endif %}
{{ comments_number }} {{ comments_label }}</a>
</span>
</p>

</div>
<div class="post-body clearfix">
<!--post summary-->

{{ content.post_list_content|safe }}
</div>
<a class="more-link" href="{{ content.absolute_url }}">Read More </a><a class="fa fa-chevron-right" href="{{ content.absolute_url }}"></a>

<hr >

{% else %}
<h2 class="post-listing-simple"><a href="{{content.absolute_url}}">{{ content.name }}</a></h2>
{% endif %}
</div>
{% endfor %}
</div>

<!--Blog-Pagination-->
{% if not simple_list_page %}
<div class="blog-pagination">
{% set page_list = [-2, -1, 0, 1, 2] %}
{% if contents.total_page_count - current_page_num == 1 %}{% set offset = -1 %}
{% elif contents.total_page_count - current_page_num == 0 %}{% set offset = -2 %}
{% elif current_page_num == 2 %}{% set offset = 1 %}
{% elif current_page_num == 1 %}{% set offset = 2 %}
{% else %}{% set offset = 0 %}{% endif %}

<div class="blog-pagination-left">
{% if last_page_num %}<a class="prev-link" href="{{ group.absolute_url }}"><i class="fa fa-angle-double-left"></i></a>{% endif %}
{% if contents.total_page_count > 5 %}
{% if current_page_num >= 4 %}
<a href="{{ group.absolute_url }}" >1</a>
<a class="elipses" href="{% if current_page_num <= 5 %}{{ group.absolute_url }}{% else %}{{ blog_page_link(current_page_num - 5) }}{% endif %}">...</a>
{% endif %}
{% endif %}
</div>
<div class="blog-pagination-center">
{% for page in page_list %}
{% set this_page = current_page_num + page + offset %}
{% if this_page > 0 and this_page <= contents.total_page_count %}
{% if this_page == 1 %}
<a {% if this_page == current_page_num %}class="active"{% endif %} href="{{ group.absolute_url }}">{{ this_page }}</a>
{% else %}
<a {% if this_page == current_page_num %}class="active"{% endif %} href="{{ blog_page_link(this_page) }}">{{ this_page }}</a>
{% endif %}
{% endif %}
{% endfor %}
</div>
<div class="blog-pagination-right">
{% if contents.total_page_count > 5 %}
{% if contents.total_page_count - current_page_num > 2 %}
<a class="elipses" href="{% if contents.total_page_count - current_page_num <= 5 %}{{ contents.total_page_count }}{% else %}{{ blog_page_link(current_page_num + 5) }}{% endif %}">...</a>
<a href="{{ blog_page_link(contents.total_page_count) }}">{{ contents.total_page_count }}</a>
{% endif %}
{% endif %}
{% if next_page_num %}<a class="next-link" href="{{ blog_page_link(current_page_num + 1) }}"><i class="fa fa-angle-double-right"></i></a>{% endif %}
</div>
</div>
{% endif %}



</div>
</div>

 

0 Upvotes
1 Accepted solution
Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Combining multiple blogs

SOLVE

Hi @Woodsy

 

to get both blogs into one listing you should create a listing containing those two(or more) blogs.

this can be done like this

{# start combining two blogs #}
{% set blog_one_posts = blog_recent_posts('123456789', limit=250) %}
{% set blog_two_posts = blog_recent_posts('987654321', limit=250) %}
{% set all_posts = (blog_one_posts + blog_two_posts) | sort(true, false, 'publish_date')  %} 
{# end combining two blogs #}

{# start listing layout #}
{# start single post layout #}
{% for post in all_posts %}
...
INSERT YOUR POST LAYOUT HERE
...
{% endfor %}
{# end sinle post layout #}
{# end listing layout #}

 

to filter them I would recomend to go to build a tag-filter.

 

 

best, 

Anton

 

Anton Bujanowski Signature

View solution in original post

3 Replies 3
nbhs_dev
Member

Combining multiple blogs

SOLVE

Hi all,

 

we followed this approach to combine get the latest posts from multiple blogs. But, we have 8 different blogs to combine and there is a hard of limit of 10 calls on "blog_recent_posts()".

Now we have various post lists in addition on the same page and we hit the limit of 10 requests per page, because of this list-combining-approach. Now we are searching for a smarter approach, because on the resulting page we only have 4 blog post lists, but the first list needs the combined posts with 8 calls. That looks pretty unsmart to me, but we did not find another solution right now.

 

Does anyone here has an idea how to overcome this limition?

Thanks

 Elmar

0 Upvotes
Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Combining multiple blogs

SOLVE

Hi @Woodsy

 

to get both blogs into one listing you should create a listing containing those two(or more) blogs.

this can be done like this

{# start combining two blogs #}
{% set blog_one_posts = blog_recent_posts('123456789', limit=250) %}
{% set blog_two_posts = blog_recent_posts('987654321', limit=250) %}
{% set all_posts = (blog_one_posts + blog_two_posts) | sort(true, false, 'publish_date')  %} 
{# end combining two blogs #}

{# start listing layout #}
{# start single post layout #}
{% for post in all_posts %}
...
INSERT YOUR POST LAYOUT HERE
...
{% endfor %}
{# end sinle post layout #}
{# end listing layout #}

 

to filter them I would recomend to go to build a tag-filter.

 

 

best, 

Anton

 

Anton Bujanowski Signature
webdew
Guide | Diamond Partner
Guide | Diamond Partner

Combining multiple blogs

SOLVE

Hi @Woodsy ,

You can use Isotope - filtering js for the filtring. you have to add HubSpot tags for filters.

Refer to this link:- https://codepen.io/desandro/pen/Ehgij

Hope this helps!


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

Thanks and Regards.

0 Upvotes