homegrade_theme_production/template-news.php

92 lines
2.5 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">
<nav class="breadcrumbs_navigation" aria-label="breadcrumbs">
<ol>
<li><a href="<?php echo home_url() ?>">Home</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>
</div>
<div class="heading-box ">
<img class="heading-box__page-icon" src="<?php echo $pageIcon['url'] ?>" alt="" />
<h1 class="heading-box__title"><?php echo get_the_title(get_queried_object_id()) ?></h1>
<p class="heading-box__description"> <?php echo __("Qu'y a-t-il de nouveau
chez Homegrade ?", "homegrade-theme__texte-fonctionnel") ?></p>
</div>
<ul class="filters-toolbar filters-toolbar--archive-news">
<?php
$news_types = get_terms(array(
'taxonomy' => 'news-type',
'hide_empty' => true,
));
?>
<li>
<button class="filter__action-button" data-term-id="all">Tous</button>
</li>
<?php foreach ($news_types as $typeTerm) : ?>
<li>
<button class="filter__action-button" data-term-id="<?php echo $typeTerm->term_id ?>"><?php echo $typeTerm->name ?></button>
</li>
<?php endforeach; ?>
</ul>
<?php
$post_per_page = 12;
$args = array(
"post_type" => "post",
"status" => "publish",
"posts_per_page" => $post_per_page,
);
$posts = new WP_Query($args);
?>
<section class="news-container">
<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>
<?php
get_footer();