現在我寫文章基本上每篇文章都會找一張特色圖像,但是還是有很多人並不會特意這樣做,他們希望當我不設置特色圖像時,如果有默認的縮略圖就太好了,下面就是一種方法:
<?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; ?>