carhop__carhop-theme__DEV/template-parts/components/archive/latest-parutions.php

42 lines
1.2 KiB
PHP

<?php
$post_amount = $args['post_amount'] ?? 1;
$post_type = $args['post_type'] ?? null;
if (!$post_type) return;
$posts_query = new WP_Query(array(
'post_type' => $post_type,
'posts_per_page' => $post_amount,
'orderby' => 'date',
'order' => 'DESC',
));
$posts = $posts_query->posts;
$current_post_type = $args['current_post_type'] ?? get_post_type();
?>
<div class="latest-parutions">
<?php if ($post_amount > 1) : ?>
<h2 class="latest-parutions__title title-small">Dernières parutions</h2>
<?php else : ?>
<h2 class="latest-parutions__title title-small">Dernière parution</h2>
<?php endif; ?>
<?php foreach ($posts as $post) : ?>
<div class="post-card post-card--analyses-etudes">
<div class="latest-parution__item">
<?php get_template_part('template-parts/components/content-meta', null, array(
'current_post_type' => $current_post_type,
'current_post_id' => $post->ID
)); ?>
<a href="<?php echo get_the_permalink($post->ID); ?>">
<?php echo get_the_post_thumbnail($post->ID, 'medium'); ?>
<h3><?php echo get_the_title($post->ID); ?></h3>
</a>
</div>
</div>
<?php endforeach; ?>
</div>