REFACTOR post-grid.php to utilize the new post-grid-toolbar component, streamlining the code by removing redundant elements and enhancing maintainability.
This commit is contained in:
parent
239f2be885
commit
439029c830
|
|
@ -1,83 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
$post_amount = $args['post_amount'] ?? -1;
|
$post_amount = $args['post_amount'] ?? -1;
|
||||||
$grid_title = $args['grid_title'] ?? 'Trouver une publication';
|
$grid_title = $args['grid_title'] ?? 'Trouver une publication';
|
||||||
|
|
||||||
$current_post_type = $args['current_post_type'] ?? get_post_type();
|
$current_post_type = $args['current_post_type'] ?? get_post_type();
|
||||||
$current_post_type_obj = get_post_type_object($current_post_type);
|
|
||||||
|
|
||||||
$posts_query = new WP_Query(array(
|
$posts_query = new WP_Query(array(
|
||||||
'post_type' => $current_post_type,
|
'post_type' => $current_post_type,
|
||||||
'posts_per_page' => $post_amount
|
'posts_per_page' => $post_amount
|
||||||
));
|
));
|
||||||
$post_count = $posts_query->post_count;
|
|
||||||
|
|
||||||
$types = get_terms(array(
|
|
||||||
'taxonomy' => 'type',
|
|
||||||
'hide_empty' => true,
|
|
||||||
));
|
|
||||||
|
|
||||||
// write_log($current_post_type_obj);
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
<section class="post-grid content-section">
|
<section class="post-grid content-section">
|
||||||
<h2 class="find-publication__title title-small"><?php echo $grid_title; ?></h2>
|
<h2 class="find-publication__title title-small"><?php echo $grid_title; ?></h2>
|
||||||
<div class="content-section__inner">
|
<div class="content-section__inner">
|
||||||
|
|
||||||
<div class="post-grid__toolbar">
|
<?php get_template_part('template-parts/components/archive/post-grid-toolbar', null, array(
|
||||||
|
'posts_query' => $posts_query,
|
||||||
<div class="search-by">
|
'current_post_type' => $current_post_type,
|
||||||
<p class="search-by__label">Filtrer par</p>
|
)); ?>
|
||||||
<div class="search-by__buttons" data-filter="thematique">
|
|
||||||
<button data-filter="thematique" aria-selected="true">Thématique</button>
|
|
||||||
<button data-filter="occurence" aria-selected="false">Mot clé</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div class="post-grid__toolbar-actions" data-post-type="revues">
|
|
||||||
<div class="search-bar">
|
|
||||||
<input type="text" placeholder="<?php _e('Rechercher par mot-clé', 'dynamiques'); ?>">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<select name="types">
|
|
||||||
<option value=""><?php _e('Tous les types', 'carhop'); ?></option>
|
|
||||||
<?php foreach ($types as $type) : ?>
|
|
||||||
<option value="<?php echo $type->slug; ?>" <?php selected($type_slug, $type->slug); ?>>
|
|
||||||
<?php echo $type->name; ?>
|
|
||||||
</option>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</select>
|
|
||||||
<select name="auteurs">
|
|
||||||
<option value=""><?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>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h2 class="post-count">
|
|
||||||
<span class="post-count__count">
|
|
||||||
<?php echo $post_count; ?>
|
|
||||||
</span>
|
|
||||||
<?php if ($post_amount > 1) : ?>
|
|
||||||
<span class="post-count__text">
|
|
||||||
<?php echo $current_post_type_obj->labels->name; ?>
|
|
||||||
</span>
|
|
||||||
<?php else : ?>
|
|
||||||
<span class="post-count__text">
|
|
||||||
<?php echo $current_post_type_obj->labels->singular_name; ?>
|
|
||||||
</span>
|
|
||||||
<?php endif; ?>
|
|
||||||
</h2>
|
|
||||||
<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>
|
|
||||||
|
|
||||||
|
|
||||||
<ul class="post-grid__list">
|
<ul class="post-grid__list">
|
||||||
<?php if (isset($posts_query) && $posts_query->have_posts()) : ?>
|
<?php if (isset($posts_query) && $posts_query->have_posts()) : ?>
|
||||||
|
|
@ -87,5 +27,6 @@ $types = get_terms(array(
|
||||||
)); ?>
|
)); ?>
|
||||||
<?php endwhile; ?>
|
<?php endwhile; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
Loading…
Reference in New Issue
Block a user