Jun 7, 201711:19 AM - edited Jun 7, 201711:19 AM
Participant
Blog Loop using specific post IDs
SOLVE
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:
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?!
{% 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.
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?
{% 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.