ADD feature 5 random posts at the end of a post #17
This commit is contained in:
parent
af2f800321
commit
1b8f77cb4b
3 changed files with 46 additions and 10 deletions
|
|
@ -14,6 +14,8 @@
|
|||
{{ post.content | safe }}
|
||||
</div>
|
||||
</article>
|
||||
|
||||
{% include 'random_posts.tmpl' %}
|
||||
</main>
|
||||
|
||||
{% include 'footer.tmpl' %}
|
||||
|
|
|
|||
23
theme/default/templates/random_posts.tmpl
Normal file
23
theme/default/templates/random_posts.tmpl
Normal 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 %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue