On my blog page I’ve taken the first 2 blog posts and made them as simple cards within my hero at the top of the page, but I want to hide them from the actual blog listings. I managed to hide them using a function but when I did they were hidden but 2 blank spots appeared at the bottom as it didn’t pull the next 2 blogs from the next page. Is there anyway I can hide the 2 blog posts before the sorting of blogs per page is done to avoid these 2 empty spaces!
Hi thank you for this! It’s almost perfect but page 1 and 2 are showing the same 6 blog posts? I’ll mark this as solution but if you could see what might be causing both pages to just display the same 6 will be really greatful!!!
@MClarke12 in that case you don’t need the blog_recent_posts functionality, you can use the variable {{contents}} for that and loop through all articles in your blog.
Then add some variables to work as “offset” when you are in other pages and use it as condition for your loop, something like this:
{# Blog listing #}
{% set page_offset = current_page_num - 1 %} {# -1 if it starts at 1 #}
{% set initial_offset = page_offset * 2 %} {# the post number it will start displaying #}
{% set final_offset = initial_offset + 6 %} {# the last post it will display #}
{% for post in contents %}
{% if loop.index > initial_offset and loop.index < final_offset %}
<article class="blog-index__post-wrapper">
<div class="blog-index__post">
{% if post.featured_image and group.use_featured_image_in_summary %}
<a class="blog-index__post-image"
style="background-image: url('{{ post.featured_image }}');"
href="{{ post.absolute_url }}">
</a>
{% endif %}
<div class="blog-index__post-content">
<div>
{% set featured_tag = post.topic_list | first %}
{% if featured_tag %}
<span class="blog-index__post-preheader">{{ featured_tag }}</span>
{% endif %}
<h3><a href="{{ post.absolute_url }}">{{ post.name }}</a></h3>
{% if content_group.show_summary_in_listing %}
<p>{{ post.meta_description | default(post.post_summary, true) | truncatehtml(150, '...', false) }}</p>
{% endif %}
</div>
<div class="blog-index__post-meta" style="display:none">
<span class="blog-index__post-author">
{{ post.blog_post_author }}
</span>
<span class="blog-index__post-date">
{{ post.publish_date | datetimeformat('%b %e, %Y') }}
</span>
</div>
</div>
</div>
</article>
{% endif %}
{% endfor %}
{# End blog listing #}
Please use the previous code as idea, don’t just copy&paste it because I didn’t try it in a live example