94 lines
2.9 KiB
PHP
94 lines
2.9 KiB
PHP
<?php
|
|
// Récupérer le paramètre etiquette de l'URL
|
|
$etiquette_slug = isset($_GET['etiquette']) ? sanitize_text_field($_GET['etiquette']) : '';
|
|
|
|
|
|
// Construire les arguments de la query
|
|
$query_args = array(
|
|
'post_type' => 'articles',
|
|
'posts_per_page' => -1,
|
|
'post_status' => 'publish',
|
|
);
|
|
|
|
// Si on a une étiquette, ajouter le filtre taxonomy
|
|
if (!empty($etiquette_slug)) {
|
|
$query_args['tax_query'] = array(
|
|
array(
|
|
'taxonomy' => 'etiquettes',
|
|
'field' => 'slug',
|
|
'terms' => $etiquette_slug,
|
|
),
|
|
);
|
|
}
|
|
|
|
$articles = new WP_Query($query_args);
|
|
$post_count = $articles->post_count;
|
|
$authors = get_posts(array(
|
|
'post_type' => 'auteurs',
|
|
'posts_per_page' => -1
|
|
));
|
|
|
|
$thematiques = get_terms(array(
|
|
'taxonomy' => 'etiquettes',
|
|
'hide_empty' => true,
|
|
));
|
|
?>
|
|
|
|
<section class="post-grid articles-grid content-section <?php echo !empty($etiquette_slug) ? 'has-initial-filter' : '' ?>">
|
|
<div class="content-section__inner">
|
|
|
|
<div class="post-grid__toolbar">
|
|
<h2 class="post-count">
|
|
<span class="post-count__count">
|
|
<?php echo $post_count; ?>
|
|
</span>
|
|
<span class="post-count__text">
|
|
<?php _e('articles', 'dynamiques'); ?>
|
|
</span>
|
|
</h2>
|
|
|
|
<div class="search-bar">
|
|
<input type="text" placeholder="<?php _e('Rechercher par mot-clé', 'dynamiques'); ?>">
|
|
</div>
|
|
|
|
<div class="post-grid__toolbar-actions">
|
|
|
|
<select name="etiquettes">
|
|
<option value=""><?php _e('Tous les tags', 'dynamiques'); ?></option>
|
|
<?php foreach ($thematiques as $thematique) : ?>
|
|
<option value="<?php echo $thematique->slug; ?>" <?php selected($etiquette_slug, $thematique->slug); ?>>
|
|
<?php echo $thematique->name; ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<select name="auteurs">
|
|
<option value="1"><?php _e('Tous·tes les auteur·e·s', 'dynamiques'); ?></option>
|
|
<?php foreach ($authors as $author) : ?>
|
|
<option value="<?php echo $author->ID; ?>"><?php echo $author->post_title; ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
|
|
<select name="sort_by">
|
|
<option value="date_desc" selected><?php _e('Numéros récents en premier', 'dynamiques'); ?></option>
|
|
<option value="date_asc"><?php _e('Numéros anciens en premier', 'dynamiques'); ?></option>
|
|
<option value="title_asc"><?php _e('Par ordre alphabétique', 'dynamiques'); ?></option>
|
|
</select>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<ul class="post-grid__list">
|
|
<?php if ($articles->have_posts()) : ?>
|
|
<?php while ($articles->have_posts()) : $articles->the_post(); ?>
|
|
<?php get_template_part('template-parts/articles/card-article', null, array(
|
|
'date' => get_the_date(),
|
|
'image' => get_the_post_thumbnail_url(),
|
|
'link' => get_the_permalink(),
|
|
'ID' => get_the_ID(),
|
|
'showAuthors' => true,
|
|
)); ?>
|
|
<?php endwhile; ?>
|
|
<?php endif; ?>
|
|
</ul>
|
|
</div>
|
|
</section>
|