?AlkantarClanX12
| Current Path : /home/rankinh/saintgilleslesbains-bis/wp-content/themes/divi-child/inc/shortcodes/ |
| Current File : /home/rankinh/saintgilleslesbains-bis/wp-content/themes/divi-child/inc/shortcodes/news.php |
<?php
/**
* Shortcode [sglb_home_news]
* Affiche 1 grand article à gauche et 3 petits à droite
*/
add_shortcode('sglb_home_news', function() {
// 1. Récupération des 4 derniers articles
$posts = get_posts([
'post_type' => 'post',
'posts_per_page' => 4,
'post_status' => 'publish'
]);
if ( empty($posts) ) return '';
// On sépare le premier du reste
$featured = array_shift($posts);
ob_start(); ?>
<div class="sglb-news-container">
<div class="news-featured">
<a href="<?php echo get_permalink($featured->ID); ?>" class="news-featured-link">
<div class="news-featured-img">
<?php echo get_the_post_thumbnail($featured->ID, 'large'); ?>
<div class="news-featured-overlay">
<h3 class="news-featured-title"><?php echo get_the_title($featured->ID); ?></h3>
<p class="news-featured-excerpt">
<?php echo wp_trim_words(get_the_excerpt($featured->ID), 20); ?>
</p>
</div>
</div>
</a>
</div>
<div class="news-list-sidebar">
<?php foreach ( $posts as $p ) : ?>
<article class="news-list-item">
<a href="<?php echo get_permalink($p->ID); ?>">
<div class="news-item-thumb">
<?php echo get_the_post_thumbnail($p->ID, 'thumbnail'); ?>
</div>
<div class="news-item-content">
<h4 class="news-item-title"><?php echo get_the_title($p->ID); ?></h4>
<p class="news-item-excerpt"><?php echo wp_trim_words(get_the_excerpt($p->ID), 12); ?></p>
</div>
</a>
</article>
<?php endforeach; ?>
</div>
</div>
<?php
return ob_get_clean();
});