homegrade_theme_production/template-news.php

125 lines
3.2 KiB
PHP

<?php /* Template Name: News */
get_header();
$args = array(
'meta_key' => '_wp_page_template',
'meta_value' => "template-news.php"
);
$relatedPageTemplatePage = get_pages($args) ? get_pages($args)[0] : null;
$pageIcon = get_field('page_icon', get_queried_object_id()) ?? null;
?>
<div class="template-archives template-archives--publications">
<?php /* --------
BREADCRUMB
---------------*/ ?>
<nav class="breadcrumbs_navigation" aria-label="breadcrumbs">
<ol>
<li>
<a href="<?php echo home_url() ?>" title="<?php echo __("Accueil", "homegrade-theme__texte-fonctionnel") ?>">
<img src="<?php echo get_template_directory_uri() . "/resources/img/pictogrammes/icon_house_dark.svg" ?>" alt="">
</a>
</li>
<li><a href="<?php echo get_the_permalink($relatedPageTemplatePage) ?>" aria-current='location'>
<?php echo __("News", "homegrade-theme__texte-fonctionnel") ?>
</a></li>
</ol>
</nav>
<?php /* --------
HEADING BOX
---------------*/ ?>
<?php
get_template_part("template-components/heading-box", null, array(
"pageIcon" => $pageIcon,
"title" => get_the_title(get_queried_object_id()),
"description" => __("Qu'y a-t-il de nouveau chez Homegrade ?", "homegrade-theme__texte-fonctionnel"),
));
?>
<?php /* --------
FILTERS
---------------*/ ?>
<ul class="filters-toolbar filters-toolbar--archive-news">
<?php
$news_types = get_terms(array(
'taxonomy' => 'news-type',
'hide_empty' => true,
));
?>
<li>
<button class="filters-toolbar__action-button" data-term-id="all">Tous</button>
</li>
<?php foreach ($news_types as $typeTerm) : ?>
<?php
$termIcon = get_field('news_type_icon', "news-type" . '_' . $typeTerm->term_id) ?? null;
?>
<li>
<button class="filters-toolbar__action-button" data-term-id="<?php echo $typeTerm->term_id ?>">
<?php if ($termIcon) : ?>
<img class="icon" src="<?php echo $termIcon['url'] ?>" alt='' />
<?php endif; ?>
<?php echo $typeTerm->name ?>
</button>
</li>
<?php endforeach; ?>
</ul>
<?php /* -------------
POSTS CARDS GRID
--------------------*/ ?>
<section class="news-container">
<?php
$post_per_page = 12;
$args = array(
"post_type" => "post",
"status" => "publish",
"posts_per_page" => $post_per_page,
);
$posts = new WP_Query($args);
?>
<div class="card-grid-container">
<?php
foreach ($posts->posts as $key => $post) {
$post_thumbnail = get_the_post_thumbnail($post->ID, 'full', array('class' => 'card-news__thumbnail card-post__thumbnail')) ?? null;
$news_type = get_the_terms($post->ID, "news-type") ?? null;
get_template_part(
'template-components/cards/card-news',
null,
array(
'card_variant' => 'activite',
'post_ID' => $post->ID,
'post_title' => $post->post_title,
'post_thumbnail' => $post_thumbnail,
'news_type' => $news_type,
)
);
}
?>
</div>
<?php if ($posts->max_num_pages > 1) : ?>
<button id="load-more-news" class="cta cta--outline cta--button mx-auto mb-32">Charger Plus</button>
<?php endif; ?>
</section>
</div>
<?php
get_footer();