Tutorials

Table of contents
Close

Printing sets of blog posts on page templates

While blog posts are generally displayed in a blog template listing or individual post layout, there are many situations where you may want to print sets of posts on a non-blog template. For example, you may want to print a set of the most recent posts on your site's homepage. 

To print posts on a non-blog template, you can either use an RSS module or HubL functions. If you are looking to learn more about HubSpot's standard blog content module and the standard blog content markup, check out this article.

RSS modules

The RSS listing module is a standard module that prints post information from a HubSpot or an external RSS feed. You can use RSS modules within template layouts, or add them to coded templates with the HubL module statement. RSS modules for HubSpot-hosted RSS feeds support featured image.

HubL functions

You can use HubL functions to retreive sets of the most recent posts, the most recent posts about a particular topic, the most recent posts by a particular author, the most popular posts. By storing the sequence of posts in a variable, you can then iterate through the posts and print each post's variables in your custom markup.

The following functions will retrieve sets of posts:

Please note that this technique does not support pagination. Pagination settings in HubSpot will only apply to standard blog listings. If you wanted to paginate content rendered with a HubL function, you would need to use Javascript to paginate the static set of posts.


{% set posts = blog_recent_posts('default', 5) %}
{% for post in posts %}
    <h3><a href="{{ post.absolute_url }}">{{ post.name }}</a></h3>
    <img src="{{ post.featured_image }}" alt="{{ post.name }}">
{% endfor %}

In the example above, the 5 most recent posts are retreived from the default blog and stored in a variable named posts. A for loop is them used to print custom post markup with each iteration.

You can use any blog post variables within your loop, but you need to replace "content" with the name of your loop item. In the example above, "content.name becomes post.name.

In addition, you can combine multiple sets of posts from different blogs into the same listing. To learn more, check out this article.