The way I usually do this is to have a "featured" tag and then use the blog_recent_tag_posts function to get the latest post. If you just want one, you could do something like this:
In the above case you're setting the function to only get one post and then using the [0] index to fetch the first item on the list, but you could also use a loop like:
{% set featured_posts = blog_recent_tag_posts("default", "featured", 1) %}
{% for post in featured_posts %}
<div class="featured-post">
<h1>{{ post.name }}</h1>
</div>
{% endfor %}
If you want to code it to be a specific post without using a tag (since you mention you don't want it to be dynamic), you could also use the content_by_id function, like this:
When I implemented the code, I was able to see the post which is tagged as 'featured', the exact feature I want, but only one post is appearing in the Second loop. Could you please check the code?
{# First loop: featured posts #}
{% for content in contents %}
{% for topic in content.topic_list %}
{% if topic.name == 'featured' %}
<div class="post-item">
{% if not simple_list_page %}
<div class="post-header">
<h2><a href="{{content.absolute_url}}">{{ content.name }}</a></h2>
</div>
<div class="post-body clearfix">
<!--post summary-->
{% if content.post_list_summary_featured_image %}
<div class="hs-featured-image-wrapper">
<a href="{{content.absolute_url}}" title="" class="hs-featured-image-link">
<img loading="lazy"src="{{ content.post_list_summary_featured_image }}" class="hs-featured-image" alt="{{ content.featured_image_alt_text | escape }}">
</a>
</div>
{% endif %}
{{ content.post_list_content|safe }}
</div>
{% endif %}
</div>
{% endif %}
{% endfor %}
{% endfor %}
{# Second loop: all other posts #}
{% for content in contents %}
{% for topic in content.topic_list %}
{% if topic.name != 'featured' %}
<h2><a href="{{content.absolute_url}}">{{ content.name }}</a></h2>
{% endif %}
{% endfor %}
{% endfor %}
Thank you for the detailed explanation. I think the last one is the code I needed. I tried it inside my blog and it worked. But I found some practical issues to implement it.
1) Actually, this feature is controlled by our client who is not familiar with editing the template.
2) Is there any method to help client to select the blog post as featured?
3) Then we also need to hide it from the remaining list.
4) Can you please explain how to use the custom module with the 'Page' field? I tried to add it but it returned the blog id + post title.
The way I usually do this is to have a "featured" tag and then use the blog_recent_tag_posts function to get the latest post. If you just want one, you could do something like this:
In the above case you're setting the function to only get one post and then using the [0] index to fetch the first item on the list, but you could also use a loop like:
{% set featured_posts = blog_recent_tag_posts("default", "featured", 1) %}
{% for post in featured_posts %}
<div class="featured-post">
<h1>{{ post.name }}</h1>
</div>
{% endfor %}
If you want to code it to be a specific post without using a tag (since you mention you don't want it to be dynamic), you could also use the content_by_id function, like this:
Join us on March 27th at 12 PM for the Digital Essentials Lab, an interactive session designed to redefine your digital strategy!
Engage with expert Jourdan Guyton to gain actionable insights, participate in live Q&A, and learn strategies to boost your business success. Don't miss this opportunity to connect and grow—reserve your spot today!
Did you know that the Community is available in other languages? Join regional conversations by changing your language settings !