As per the image below - I have a blog archive page which shows a featured blog post as a large one and then shows all of the blog posts below that.
I would like to add something to the main blog loop to say:
IF the blog blog post is featured, don't display it here
So I can stop duplicate blog posts showing up (one featured and then the same one in the main blog loop).
I have two bits of code, one that pulls the featured post through and one that loops all of the posts through. Here
<!-- Featured Blog Item -->
<?php
$loop = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_key' => 'featured',
'meta_value' => 'yes'
)
);
?>
<div class="container">
<div class="row no-gutters">
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-12">
<a href="<?php the_permalink(); ?>">
<div class="hero__overlay featured-grad-blog">
</div>
</a>
<div class="featured-blog-container">
<h3><?php the_title(); ?></h3>
<p><?php the_date(); ?></p>
</div>
<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<div class="featured-blog-grid-image-container" style="background-image:url(<?php echo $feat_image; ?>);"></div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
</div>
<!-- All Blog Items -->
<?php
$loop = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => -1
)
);
?>
<div class="container blog-page-container">
<div class="row blog-page-row">
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-lg-4 col-sm-6 col-xs-12 blog-page-col">
<div class="blog-image" style="position: relative;">
<a href="<?php the_permalink(); ?>">
<div class="hero__overlay grad-blog-hover"></div>
</a>
<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<div class="blog-grid-image-container blog-page-image blog-post-image-div" style="background-image:url(<?php echo $feat_image; ?>);"></div>
</div>
<div class="blog-title">
<a href="<?php the_permalink(); ?>">
<h4><?php the_title(); ?></h4>
</a>
</div>
<div class="blog-bars-outside-container">
<div class="blog-bars-inside-container">
<div class="blog-all-bar blog-bar1"></div>
<div class="blog-all-bar blog-bar2"></div>
<div class="blog-all-bar blog-bar3"></div>
<div class="blog-all-bar blog-bar4"></div>
<div class="blog-all-bar blog-bar5"></div>
</div>
</div>
<div class="blog-excerpt">
<?php the_excerpt(); ?>
</div>
<div class="meta-details">
<p><?php the_author_meta( 'display_name', $author_id ); ?> - <?php echo get_the_date(); ?></p>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
</div>
I guess I would need to add the opposite of this maybe, into the array for the main blog posts:
'meta_key' => 'featured',
'meta_value' => 'yes'
But I can't get anything to work...
Any help would be greatly appreciated!