首页 > 解决方案 > 如何为用户未设置的帖子设置缩略图

问题描述

如果用户在创建帖子时没有选择缩略图,我希望主题为帖子设置缩略图。

我尝试浏览 WordPress 法典,但我可以找到任何“设置方法”。

<div class="standard-featured">
    <?php if( has_post_thumbnail() ) { ?>
        <?php the_post_thumbnail(); ?>
    <?php } else { ?>
        <img src="//Set your image default Path here.">
    <?php } ?>
</div>

标签: wordpress

解决方案


有很多方法可以做到这一点。这是一种更清洁的方法。下面的代码示例。

<?php if( has_post_thumbnail() ) : ?>

  <?php the_post_thumbnail() ?>

<?php else : ?>

  // Dafult thumbnail image for post. try to write the exact image location.
  <img src="default.jpg" />

<?php endif; ?>

推荐阅读