user12160926
user12160926

Reputation:

Ignore thumbnail space if there is no thumbnail

So I have the below code that loops through my posts and displays posts in a list format. Here is the code that I'm using:

<?php while (have_posts()) : the_post(); ?>
    <div class="one-sixth first"><?php the_post_thumbnail(); ?></div>
    <div class="five-sixths"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
<?php endwhile; ?>

Here is the image with the thumbnail:
enter image description here

Here is when no post thumbnail is available, it just leaves an empty space:
enter image description here

Upvotes: 1

Views: 44

Answers (1)

vadivel a
vadivel a

Reputation: 1794

If check thumbnail if have displayed otherwise display placeholder image. Hope this help you.

<?php
// Must be inside a loop.

if ( has_post_thumbnail() ) {
    the_post_thumbnail();
}
else {
    echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) 
        . '/images/placeholder.jpg" />';
}
?>

Upvotes: 1

Related Questions