Post placeholders

Ever have a layout set on a fixed number of posts that sometimes stops short? Ever wanted an easy solution for creating placeholder to fill those empty spaces?

Here ya go.

$new_query = new WP_Query( 'posts_per_page' => 9, ); // adjust number as needed
Just after you're query that looks something like this:
$posts_per_page = $new_query->get( 'posts_per_page' );
$post_count = $new_query->post_count;
$placeholders_needed = $posts_per_page - $post_count;
Add the following:
if ( $placeholders_needed > 0 ) : 
    foreach ( range( 1, $placeholders_needed ) as $current_placeholder ) :
	echo 'ADD YOUR PLACEHOLDER CONTENT';
endforeach; endif;
Then, after your loop's endwhile, add the following:

Insert the content you want to make the series of posts display seamlessly, the placeholder filling in for however many posts you fall short.

Thnx @Rarst heart

Jenny Beaumont

Jenny Beaumont is an Agile Coach and the Director of Delivery at Human Made, makers of Altis DXP. She speaks at conferences around the world (ok, these days only on zoom), and is a former lead organizer of WordCamp Paris and WordCamp Europe.

Follow me on Twitter | Subscribe to my newsletter