ADD feature 5 random posts at the end of a post #17

This commit is contained in:
Caffeine Fueled 2025-10-23 22:41:36 +02:00
parent af2f800321
commit 1b8f77cb4b
Signed by: cf7
GPG key ID: CA295D643074C68C
3 changed files with 46 additions and 10 deletions

View file

@ -14,6 +14,8 @@
{{ post.content | safe }}
</div>
</article>
{% include 'random_posts.tmpl' %}
</main>
{% include 'footer.tmpl' %}

View file

@ -0,0 +1,23 @@
{% if all_posts %}
{# Filter out pages and current post, then randomly select 5 #}
{% set available_posts = all_posts | selectattr('type', 'ne', 'page') | list %}
{% if post %}
{% set available_posts = available_posts | rejectattr('slug', 'equalto', post.slug) | list %}
{% endif %}
{% if available_posts %}
{% set random_posts = available_posts | random_sample(5) %}
{% if random_posts %}
<div class="random-posts">
<h3>More Posts</h3>
<ul>
{% for p in random_posts %}
<li>
<a href="{{ p.url }}">{{ p.title }}</a>
<span class="date">{{ p.date }}</span>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endif %}
{% endif %}