【问题标题】:hide post thumbnail if there isn't a featured image如果没有特色图片,则隐藏帖子缩略图
【发布时间】:2016-02-28 20:37:43
【问题描述】:

我使用此代码在相关帖子中设置图像。 如果帖子中没有特色图片,我会隐藏缩略图。

我的代码是:

<div class="item">
                  <figure class="entry-image">
                      <a href="<?php the_permalink(); ?>">
                        <?php 
                        if ( has_post_thumbnail() ) {
                        the_post_thumbnail( 'rectangle-size-small' );

                        } elseif( first_post_image() ) { // Set the first    image from the editor
                            echo '<img src="' . first_post_image() . '"     class="wp-post-image" />';
                        } ?>
                      </a>
                  </figure>
                  <header class="entry-header">
                      <h4>
                          <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
                      </h4>
                  </header>
            </div>

我如何替换 the_post_thumbnail('rectangle-size-small'); 隐藏缩略图?

谢谢

【问题讨论】:

  • “隐藏”是一个形容词。你想说“隐藏”两次。
  • 对不起。是的,我的意思是隐藏。可以隐藏缩略图吗?

标签: php wordpress


【解决方案1】:

has_post_thumbnail() 函数检查是否有特色图片,因此如果没有提供特色图片,则不会显示。

【讨论】:

  • 在这种情况下显示图像(图像黄色 --> 'rectangle-size-small' )因为我插入了代码 the_post_thumbnail( 'rectangle-size-small' );我在这一行中进行了哪些更改以不显示缩略图?
  • 但是,正如我所说,这不会显示,因为如果您没有设置特色图像,那么 has_post_thumbnail() 将返回 false。我不太确定你在问什么,但如果你说它显示黄色图像,那么如果你不希望它显示就删除该行?
猜你喜欢
  • 2020-04-07
  • 2016-11-21
  • 1970-01-01
  • 1970-01-01
  • 2019-03-22
  • 1970-01-01
  • 2014-09-09
  • 1970-01-01
  • 2011-11-01
相关资源
最近更新 更多