In the category post archive, I want to display the last 10 posts and 1 featured post (featured post only on the first page).
I can choose a featured post that will be displayed first (user can select manually, its custom field is called ‘category_featured_post’ ). Now if the featured post is the same post that will be displayed in a list, It will be doubled (on featured position and on the list). I can hide this post on the list (if it is displayed on the first page where the featured post is displayed), but now there will be 9 posts on the list instead of 10. How can I display 10 posts in that case?
Custom field category_featured_post
is on category, it is a Post Object that returns a single post ID.
Here is the code I have now:
<!-- DISPLAY FEATURED POST (ONLY ON FIRST PAGE) IN BIG TILE -->
<?php
if ( !is_paged() ) :
$post = get_post($featured_post);
?>
<div class="tile">
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p>
<a href="<?php echo the_permalink(); ?>">Read post</a>
</div>
<?php
endif;
?>
<!-- DISPLAY POSTS IN LIST -->
<?php
if (have_posts()){
while(have_posts()){
the_post();
// DON'T DISPLAY POST IF IT'S FEATURED
if(get_the_ID() != $featured_post ){
get_template_part('template-parts/post/content','archive');
}
}
}
?>