How to show static placeholder when less post elements in archive page?

There are two kinds of loops in PHP:

  • With a unknown amount of elements ( while(), foreach(), do() while, etc)
  • With a specific number of elements (for() )

You need a loop with a specific number of elements (in this case 12 elements). So a while loop is not what you need. At first take a look at the loop which is normaly used in WordPress

$posts = new WP_Query( 'numberposts=12' );
echo '<ol>';

while( $posts->have_posts() ) {
  $posts->the_post();
    $title = get_the_title();
    echo '<li>' . $title . '</li>';
}

echo '</ol>';

This loop display posts as long as there are any posts left. If there are only five posts, only five posts will be displayed.

Let assume you have only five posts, but want to display 12 list elements. Let start with a loop which will create 12 list elements.

echo '<ol>';
for( $number = 0; $number < 12; $number++ ) {
  // create list element
}
echo '</ol>';

Now we need a switch inside our loop to decide if there is another post to display or not. If there is another post, display the post title. If not, display something else like a placeholder.

echo '<ol>';
  for( $number = 0; $number < 12; $number++ ) {

   if( $number < $post_count ) {
     // display post
   } else {
     //display placeholder
   }

echo '</ol>';

As long as the number of the current loop item is smaller as the amount of all posts, display a post, else display the placeholder.

Now we just need the number of posts. This is quiet easy: $post_count = $posts->post_count;

$posts = new WP_Query( 'numberposts=12' );
$post_count = $posts->post_count;

    echo '<ol>';

    for( $number = 0; $number < 12; $number++ ) {

      if( $number < $post_count ) {
        // display the post
        $posts->the_post();
        $title = get_the_title();
        echo '<li>' . $title . '</li>';

      } else {
        //display the placeholder
        echo '<li>No more posts</li>';

      }
    }

    echo '</ol>';

I hope this will help and clarify the difference between a while-loop and a for-loop.