switching from get_recent posts to wp query

This commit is contained in:
Antoine M 2023-11-30 17:50:31 +01:00
parent d89a2daa44
commit d6d20c5ae2

View File

@ -11,19 +11,25 @@ $block_titling_datas = get_field('block_titling_datas');
<div class="articles_container"> <div class="articles_container">
<?php <?php
$args = wp_get_recent_posts(array( $args = array(
'posts_per_page' => 4,
'post_type' => 'post', 'post_type' => 'post',
'orderby' => 'post_date', 'orderby' => 'post_date',
'order' => 'DESC', 'order' => 'DESC',
'numberposts' => 4, // Number of recent posts thumbnails to display
'post_status' => 'publish' // Show only the published posts 'post_status' => 'publish' // Show only the published posts
)); );
$recent_posts = new WP_Query($args); $recentNewsPosts = new WP_Query($args);
// echo '<pre>';
// print_r($recentNewsPosts);
// echo '</pre>';
foreach ($recent_posts->posts as $key => $post) { ?>
<?php if ($recentNewsPosts->have_posts()) : while ($recentNewsPosts->have_posts()) : $recentNewsPosts->the_post(); ?>
<?php
$post_thumbnail = get_the_post_thumbnail($post->ID, 'full', array('class' => 'card-news__thumbnail')); $post_thumbnail = get_the_post_thumbnail($post->ID, 'full', array('class' => 'card-news__thumbnail'));
$post_tags = get_the_tags($post->ID); $news_type = get_the_terms($post->ID, "news_type") ?? null;
get_template_part( get_template_part(
'template-components/cards/card-news', 'template-components/cards/card-news',
@ -31,14 +37,26 @@ $block_titling_datas = get_field('block_titling_datas');
array( array(
'card_variant' => 'activite', 'card_variant' => 'activite',
'post_ID' => $post->ID, 'post_ID' => $post->ID,
'post_title' => $post->post_title, 'post_title' => get_the_title(),
'post_thumbnail' => $post_thumbnail, 'post_thumbnail' => $post_thumbnail,
'post_tags' => $post_tags, 'news_type' => $news_type,
'post_date' => $post_date,
) )
); );
}
?> ?>
<?php endwhile ?>
<?php endif ?>
</div> </div>
<?php
$args = array(
'meta_key' => '_wp_page_template',
'meta_value' => "template-archive-news.php"
);
$relatedPageTemplatePage = get_pages($args) ? get_pages($args)[0] : null;
?>
<a id="see-all-news" class="cta cta--button cta--outline cta--button cta--centered cta--see-all" href="<?php echo get_the_permalink($relatedPageTemplatePage) ?>">
<?php echo __("Lire les autres articles", "homegrade-theme__texte-fonctionnel__publications-archive-brochures") ?>
</a>
</section> </section>