WordPress.org

Ready to get started?Download WordPress

Forums

Exclude posts with featured image from loop (1 post)

  1. oneeyedpauly
    Member
    Posted 1 year ago #

    This may seem an odd request but I'm looking for a way to display a list of posts excluding any that have a featured image.

    I have a row of four posts which include the most recent four posts with a featured image. I would then like to display all the other posts that DO NOT have a featured image as links underneath.

    This is what I've come u with so far:

    <div class="row">
    	<?php
    	global $post;
    	$args = array( 'numberposts' => 4, 'category' => 10,'meta_key'=>'_thumbnail_id', );
    	$myposts = get_posts( $args );
    	foreach( $myposts as $post ) :	setup_postdata($post); ?>
    		<li class="span2">
    		<a href="<?php the_permalink() ?>">
    			<div class="featured-blog">
    			<?php the_post_thumbnail( 'post' ); ?>
    			<h3><?php the_title(); ?></h3>
    			<p><?php the_time('d/m/y:') ?> - <?php the_excerpt(); ?></p>
    			</div>
    		</a>
    		</li>
    	<?php endforeach; ?>
    </div>
    
    <div class="row">
    	<div class="span2">
    	<h3>Other News</h3>
    	</div>
    
    	<div class="span3">
    	<?php
    	global $post;
    	$args = array( 'numberposts' => 4, 'category' => 10 );
    	$myposts = get_posts( $args );
    	foreach( $myposts as $post ) :	setup_postdata($post); ?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    	<?php endforeach; ?>
    	</div>
    
    	<div class="span3">
    	<?php
    	global $post;
    	$args = array( 'numberposts' => 4, 'offset' => 4, 'category' => 10 );
    	$myposts = get_posts( $args );
    	foreach( $myposts as $post ) :	setup_postdata($post); ?>
    		<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    	<?php endforeach; ?>
    	</div>
    </div>

Topic Closed

This topic has been closed to new replies.

About this Topic