carhop__plugins__PROD-DEV/plugins/carhop-blocks/build/featured-news/render.php
Antoine M 5dc6ea260d
All checks were successful
continuous-integration/drone/push Build is passing
CHORE REFACTOR upgrading plugin to handle a unique monopackage bundler
2025-11-20 11:06:56 +01:00

132 lines
3.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
$limit = 6;
$featured_items = array();
// QUERY ACTUALITES et AJOUT DES POSTS AU TABLEAU $featured_items
switch_to_blog(1);
$actualites = new WP_Query(array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $limit,
'orderby' => 'date',
'order' => 'DESC',
));
if ($actualites->have_posts()) {
while ($actualites->have_posts()) {
$actualites->the_post();
$featured_items[] = array(
'blog_id' => get_current_blog_id(),
'id' => get_the_ID(),
'title' => get_the_title(),
'excerpt' => get_the_excerpt(),
'permalink' => get_permalink(),
'timestamp' => (int) get_post_time('U', true),
'type' => 'post',
);
}
wp_reset_postdata();
}
restore_current_blog();
// QUERY REVUES et AJOUT DES POSTS AU TABLEAU $featured_items
switch_to_blog(2);
$revues = new WP_Query(array(
'post_type' => 'revues',
'post_status' => 'publish',
'posts_per_page' => $limit,
'orderby' => 'date',
'order' => 'DESC',
));
if ($revues->have_posts()) {
while ($revues->have_posts()) {
$revues->the_post();
$featured_items[] = array(
'blog_id' => get_current_blog_id(),
'id' => get_the_ID(),
'title' => get_the_title(),
'excerpt' => get_the_excerpt(),
'permalink' => get_permalink(),
'timestamp' => (int) get_post_time('U', true),
'type' => 'revues',
);
}
wp_reset_postdata();
}
restore_current_blog();
// Tri global par date DESC et limitation à $limit
\usort($featured_items, function ($a, $b) {
return $b['timestamp'] <=> $a['timestamp'];
});
$featured_items = \array_slice($featured_items, 0, $limit);
?>
<section class="featured-news alignfull" <?php echo get_block_wrapper_attributes(); ?>>
<div class="featured-news__inner">
<div class="featured-news__header">
<h2 class="block-title">À la une</h2>
<h3 class="block-subtitle">Le fil dactualité du carhop</h3>
</div>
<div class="featured-news__slider-content">
<div class="swiper featured-news-swiper">
<div class="swiper-wrapper">
<?php if (!empty($featured_items)) : ?>
<?php foreach ($featured_items as $item) : ?>
<?php
$current_blog_id = get_current_blog_id();
$did_switch = false;
if ($item['blog_id'] !== $current_blog_id) {
switch_to_blog($item['blog_id']);
$did_switch = true;
}
get_template_part('template-parts/dynamiques/article-card', null, array(
'ID' => $item['id'],
'isSwiperSlide' => true,
'showCover' => true,
));
if ($did_switch) {
restore_current_blog();
}
?>
<?php endforeach; ?>
<?php endif; ?>
</div>
<div class="swiper-pagination-fraction"></div>
<div class="swiper-pagination"></div>
<div class="swiper-controls">
<div class="swiper-button-prev">
<?php
$previous_arrow_icon = get_template_directory() . '/resources/img/elements/carhop-slider-previous.svg';
if (file_exists($previous_arrow_icon)) {
echo file_get_contents($previous_arrow_icon);
}
?>
</div>
<div class="swiper-button-next">
<?php
$next_arrow_icon = get_template_directory() . '/resources/img/elements/carhop-slider-next.svg';
if (file_exists($next_arrow_icon)) {
echo file_get_contents($next_arrow_icon);
}
?>
</div>
</div>
</div>
</div>
</div>
</section>