CMS Development

Evergreen
Member

How do I add the blog to my Homepage with a custom HTML template?

SOLVE

Not sure how to add a blog loop to my homepage of a custom HTML template?

 

Keeley

0 Upvotes
1 Accepted solution
Jsum
Solution
Key Advisor

How do I add the blog to my Homepage with a custom HTML template?

SOLVE

@Evergreen,

 

You can use a HubL function. Specifically this one.

 

{% set rec_posts = blog_recent_posts('default', 5) %}
{% for rec_post in rec_posts %}
    <div class="post-title">{{ rec_post.name }}</div>
{% endfor %}

First line sets a var array of posts. Default stands for the default blog. You can replace this with a blog ID if needed. The 5 is the limit on posts to return. change this to the number of blog posts you would like to recieve back.

 

The second through fourth line is a for loop that iterates through the returned posts. Place your post item markup here like you would in the for contents loop of the blog. Use all the same variables you would in your blog markup but instead of content. You would use the single item name in your for loop.

 

 

 

 

View solution in original post

1 Reply 1
Jsum
Solution
Key Advisor

How do I add the blog to my Homepage with a custom HTML template?

SOLVE

@Evergreen,

 

You can use a HubL function. Specifically this one.

 

{% set rec_posts = blog_recent_posts('default', 5) %}
{% for rec_post in rec_posts %}
    <div class="post-title">{{ rec_post.name }}</div>
{% endfor %}

First line sets a var array of posts. Default stands for the default blog. You can replace this with a blog ID if needed. The 5 is the limit on posts to return. change this to the number of blog posts you would like to recieve back.

 

The second through fourth line is a for loop that iterates through the returned posts. Place your post item markup here like you would in the for contents loop of the blog. Use all the same variables you would in your blog markup but instead of content. You would use the single item name in your for loop.