# Blog Loop using specific post IDs

**URL:** <https://community.hubspot.com/t/blog-loop-using-specific-post-ids/2287>\
**Category:** CMS Development\
**Created:** [June 7, 2017, 3:19pm UTC](https://community.hubspot.com/t/blog-loop-using-specific-post-ids/2287 "2017-06-07T15:19:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlow87](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tlow87/32/97052_2.png) [@tlow87](https://community.hubspot.com/u/tlow87)\
**Post date:** [June 7, 2017, 3:19pm UTC](https://community.hubspot.com/t/blog-loop-using-specific-post-ids/2287/1 "2017-06-07T15:19:21Z")

</div>

I’m brand new to HubL, and doing my best to grasp how the functions could work together to help me achieve this. I would like to find a simple way to loop in some blog posts, but be able to specify which post IDs I want to display. Below is my terrible attempt at communicating this to you:

```auto
<div class="recent-posts-wrapper">
 {% set rec_posts = blog_post_by_id(1491343965, 3677064533, 3676346832) %}
 {% for rec_post in rec_posts %}
 <div class="recent-item span4">
 <a href="{{ rec_post.absolute_url }}"><img src="{{ rec_post.featured_image }}" alt=""></a>
 <a href="{{ rec_post.absolute_url }}"><h4 class="post-title">{{ rec_post.name }}</h4></a>
 <p class="post-summary">{{ rec_post.post_body|striptags|truncatehtml(200, '' , false) }}</p>
 </div>
 {% endfor %}
</div>

```

As you can see, I’m taking the default Recent Posts HubL module, but want to define the three posts that will display. Could someone point out my flaws so I can become better?!

---

<div class="post-metadata">

**Author:** ![tlow87](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tlow87/32/97052_2.png) [@tlow87](https://community.hubspot.com/u/tlow87)\
**Post date:** [June 7, 2017, 3:32pm UTC](https://community.hubspot.com/t/blog-loop-using-specific-post-ids/2287/2 "2017-06-07T15:32:22Z")

</div>

P.S., my immediate thought would be to place the posts I want displayed into a particular topic, and loop that topic in. But I would want this topic to be invisible to the public. Perhaps a possibility?

---

<div class="post-metadata">

**Author:** ![JasonRosa](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jasonrosa/32/56551_2.png) [@JasonRosa](https://community.hubspot.com/u/JasonRosa)\
**Post date:** [June 7, 2017, 6:17pm UTC](https://community.hubspot.com/t/blog-loop-using-specific-post-ids/2287/3 "2017-06-07T18:17:17Z")

</div>

@tlow87 you could try something like this:

{% set rec\_posts = blog\_recent\_posts(‘default’, 200) %}  
{% for rec\_post in rec\_posts %}  
{% if rec\_post.id == ‘YOUR BLOG POST ID’ %}  
\<div class=“post-title”\>{{ rec\_post.name }}\</div\>  
{{ rec\_post.id }}  
{% endif %}  
{% endfor %}

There is a limit of 200 posts that are grabbed in the function so it won’t work if the posts you want are not within the most recent 200 posts. If you wanted to pull in multiple post ids you could use an or in the if statement so something like:

{% if rec\_post.id == ‘YOUR BLOG POST ID 1’ or rec\_post.id == ‘YOUR BLOG POST ID 2’%}

Your alternative of doing a topic that is hidden could also work. To hide it from listing you might have to do similar if or unless statements if you list your topics out anywhere so that it doesn’t show in the topic listings if that makes sense.

I hope that this helps!

---

<div class="post-metadata">

**Author:** ![tlow87](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tlow87/32/97052_2.png) [@tlow87](https://community.hubspot.com/u/tlow87)\
**Post date:** [June 8, 2017, 12:10am UTC](https://community.hubspot.com/t/blog-loop-using-specific-post-ids/2287/4 "2017-06-08T00:10:58Z")

</div>

Thanks Jason! That did the trick. Below is the code I used to place the posts into three columns.

```auto
<div class="recent-posts-wrapper">
{% set rec_posts = blog_recent_posts('default', 200) %}
{% for rec_post in rec_posts %}
{% if rec_post.id == '1491343965' or rec_post.id == '3677064533' or rec_post.id == '3676346832' %}
 <div class="recent-item span4">
 <a href="{{ rec_post.absolute_url }}"><img src="{{ rec_post.featured_image }}" alt=""></a>
 <a href="{{ rec_post.absolute_url }}"><h4 class="post-title">{{ rec_post.name }}</h4></a>
 <p class="post-summary">{{ rec_post.post_body|striptags|truncatehtml(200, '' , false) }}</p>
 </div>
{% endif %}
{% endfor %}
</div>

```

---

<div class="post-metadata">

**Author:** ![emilushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/emilushi/32/8932_2.png) [@emilushi](https://community.hubspot.com/u/emilushi)\
**Post date:** [June 3, 2020, 8:45pm UTC](https://community.hubspot.com/t/blog-loop-using-specific-post-ids/2287/5 "2020-06-03T20:45:18Z")

</div>

I see that this is already marked as resolved but there is a function for doing that:

You can use

`content_by_id OR content_by_ids`

```auto
{% set contents = content_by_ids([4715624297, 4712623297, 5215624284]) %}
<ul>
{% for content in contents %}
 <li>
 <a href="{{ content.absolute_url }}">{{content.title}}</a>
 </li>
 {% endfor %}
</ul>

```

> **[HubL functions - HubSpot docs](https://developers.hubspot.com/docs/cms/reference/hubl/functions)**
>
> A reference listing of all of the available HubL functions.
