Blog template markup
- Professional or Enterprise
- Professional or Enterprise
HubSpot blogs consist of blog listing pages and the individual blog posts. In addition to listing the individual blog posts, the blog listing template is also used for rendering the author and tag listing pages. You can either create a single template to render all listing and blog post pages, or you can create two separate templates.
Below, learn about blog template markup, template components, and customization options.
To create one template that renders the listing and post pages, add the
templateType: blog annotation to the top of your template file. When using one template to render both, you'll use an if statement that evaluates whether the user is looking at a listing page or an individual post. If you are using the drag and drop design manager layouts, this
if statement is built into the UI of blog content module buttons.
if statement, you'll write both your post and listing code.
Alternatively, you can choose to have a separate template for blog post and listing pages. This allows your code to be cleaner and easier to read as a developer, and makes the templates easier to select for content creators. The CMS boilerplate has a separate listing template and post template. If you build separate post and listing templates, this
is_listing_view check is not required, you only need to make sure to select the separate templates in Settings > Website > Blog > Templates.
Within the standard HubSpot blog listing markup, there is an
if blog_author statement. This statement evaluates to true when you are looking at an author listing page. An author listing page is a page of posts by a single author. The boilerplate template includes the author's name, bio, and social media accounts.
In addition to the if
blog_author statement that defines markup that should only render on author listing pages, there is a
tag variable that can be used to only render code on a blog topic listing page. The example below is a snippet that uses the page title variable to automatically print the tag name at the top of a tag listing page. This snippet could be added to your blog listing code.
Within the for loop, there is an
if statement that determines what to render in a simple versus regular listing.
- A simple listing is a listing of all your posts and does not support pagination. The simple listing is not affected by the post limit blog setting and generally just contains links to the most recent 200 blog posts.
- The regular listing iterates through the number of posts specified by the post listing blog setting and paginates accordingly.
The address of your simple listing page is the URL for your blog with
/all added to the end of the path.
The following code is a simplified version of this
if statement that defines what should be iterated in a simple listing page. Notice the
if statement uses reverse logic; therefore, the
else defines the simple listing view. Optionally you could use an unless statement instead.
Blog post author information is also available within the
Thank you for your feedback, it means a lot to us.