FEATURE introducing component
This commit is contained in:
parent
7b4454b8f4
commit
115bc14ff7
51
template-parts/authors/authors-last-publications.php
Normal file
51
template-parts/authors/authors-last-publications.php
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
$postId = $args['postId'] ?? get_the_ID();
|
||||||
|
$authors = get_field('authors', $postId);
|
||||||
|
$isArticle = is_singular('articles');
|
||||||
|
|
||||||
|
if ($isArticle) {
|
||||||
|
$authors = get_field('authors', $postId);
|
||||||
|
} else {
|
||||||
|
$authors = getRevueAuthors($postId);
|
||||||
|
}
|
||||||
|
if (empty($authors)) return;
|
||||||
|
|
||||||
|
|
||||||
|
// Construire une meta_query avec OR pour chaque auteur
|
||||||
|
$meta_query = array('relation' => 'OR');
|
||||||
|
foreach ($authors as $author) {
|
||||||
|
$meta_query[] = array(
|
||||||
|
'key' => 'authors',
|
||||||
|
'value' => '"' . $author->ID . '"', // Recherche la valeur sérialisée
|
||||||
|
'compare' => 'LIKE'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$authorsLastPosts = get_posts(array(
|
||||||
|
'post_type' => $isArticle ? 'articles' : 'revues',
|
||||||
|
'posts_per_page' => 6,
|
||||||
|
'orderby' => 'date',
|
||||||
|
'order' => 'DESC',
|
||||||
|
'meta_query' => $meta_query,
|
||||||
|
));
|
||||||
|
|
||||||
|
if (empty($authorsLastPosts) || count($authorsLastPosts) < 2) return;
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="authors-last-publications">
|
||||||
|
<?php if (count($authors) <= 1) : ?>
|
||||||
|
<h3 class="title-small">Ses dernières publications</h3>
|
||||||
|
<?php else : ?>
|
||||||
|
<h3 class="title-small">Leurs dernières publications</h3>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php foreach ($authorsLastPosts as $post) : ?>
|
||||||
|
<?php get_template_part('template-parts/articles/card-article', null, array(
|
||||||
|
'ID' => $post->ID,
|
||||||
|
'showAuthors' => true,
|
||||||
|
)); ?>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php wp_reset_postdata(); ?>
|
||||||
Loading…
Reference in New Issue
Block a user