现在我写文章基本上每篇文章都会找一张特色图像,但是还是有很多人并不会特意这样做,他们希望当我不设置特色图像时,如果有默认的缩略图就太好了,下面就是一种方法:
<?php if(has_post_thumbnail()) : ?>
<a class="post-thumbnail" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('thumbnail', ['class' => 'card-img-top']); ?>
</a>
<?php else: ?>
<a class="post-thumbnail" href="<?php the_permalink(); ?>">
<img src="<?php echo get_template_directory_uri();?>/assets/img/placeholder.png" class="card-img-top"/>
</a>
<?php endif; ?>