I need to build an 'announcement' banner showing the 5 latest posts, of which one MUST
be the latest newsletter.
What I want to do: latest 4 posts excluding newsletter category + latest newsletter post as the 5th post.
How is this possible?
I have tried tax_query
, but then it only shows the newsletter
category, and does not limit that specific category.
I have tried excluding all post IDs from the newsletter
category, but then if there are no newsletters in the latest 5 posts, it does not show the latest newsletter at all.
Code:
$category_id = get_cat_ID('Newsletter');
$latest_newsletter = query_posts("cat=$category_id&order_by=date");
$exclude_ids = [];
$count = 0;
while (have_posts()) : the_post();
$post = get_post();
if($count > 0) {
$exclude_ids[] = $post->ID;
}
$count++;
endwhile;
wp_reset_query();
query_posts(['posts_per_page' => '4', 'order_by' => 'date', 'post__not_in' => $exclude_ids]); if (have_posts()) : ?>
<div class="news-announcement">
<h3>ANNOUNCEMENT</h3>
<div id="ticker" class="ticker">
<ul>
<?php while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="Continue reading"> continue reading...</a>
<?php the_title( ); ?></li>
<?php endwhile; ?>
</ul>
</div>
</div>
Any ideas?