grav-theme-future2021/templates/partials/miniposts.html.twig
2023-07-13 21:50:36 +02:00

54 lines
2.6 KiB
Twig

{# Configuring miniposts with variables defined in the theme #}
{% set miniposts_category = theme_var('miniposts_category') %}
{% set miniposts_number = config.theme.miniposts_number %}
{% set lang = grav.language.getActive ?: grav.config.site.default_lang %}
<section>
<header class="">
<h3>{{ 'FUTURE.FEATURED'|t }}</h3>
</header>
<div class="mini-posts">
{% for p in page.evaluate({'@taxonomy.category':miniposts_category}).order('header.order', 'asc').slice(0,miniposts_number) %}
{% if p.header.metadata.author %}
{% set author = p.header.metadata.author %}
{% elseif p.header.author %}
{% set author = p.header.author %}
{% else %}
{% set author = p.taxonomy.author[0] %}
{% endif %}
{% set title = p.title|raw %}
{% set avatar = p.media[p.header.avatarImage].url|e %}
{% set image = p.media[p.header.primaryImage] ?: p.media.all|filter((v, k) => k != p.header.avatarImage and (v.type == 'image' or v.type == 'vector'))|first %}
{# Define if the primary image and the attributes of width and height are shown #}
{% set show_image = p.header.show_pageimage|defined(true) %}
{% set img_width = p.header.image_width|default(1038) %}
{% set img_height = p.header.image_height|default(437) %}
<article class="mini-post">
<header>
<h3>
<a href="{{ p.url }}" aria-label="{{ title }}">{{ title }}</a>
</h3>
{% if config.plugins["translate-date"].enabled %}
<time class="published" itemprop="datePublished" datetime="{{ page.date|td(null, "Y-m-d") }}">{{ page.date|td(null, "M j, Y") }}</time>
{% elseif config.plugins["twig-extensions"].enabled %}
<time class="published" itemprop="datePublished" datetime="{{ page.date|localizeddate('medium', 'none', lang) }}">{{ page.date|localizeddate('medium', 'none', lang) }}</time>
{% else %}
<time class="published" itemprop="datePublished" datetime="{{ page.date|date("Y-m-d") }}">{{ page.date|date("M j, Y") }}</time>
{% endif %}
{% if avatar %}
<a href="{{ p.url }}" class="author" title="{{ author }}"><img src="{{ avatar }}" alt="{{ author }}"/></a>
{% endif %}
</header>
{% if show_image and image %}
<a href="{{ p.url }}" class="image" title="{{ title|raw }}" rel="nofollow">
{{ image.cropZoom(img_width,img_height).loading('lazy').attribute('decoding','async').html(title,title)|raw}}
</a>
{% endif %}
</article>
{% endfor %}
</div>
</section>
<!-- End of featured Section -->