如何隐藏某些帖子中的精选图片

时间:2012-11-28 02:05:11

标签: wordpress

有没有办法隐藏某些帖子中的精选图片?

我的博客是cur-mudg-eon.com,如果你看一下标题为“孔子说......”的最新帖子(在主页上),你会看到我使用了特色图片并显示了一些摘录文本。当您点击标题或图片时,它会将您带到显示我想要显示的卡通的帖子,以及我想隐藏/删除的特色图片。

我只想在某些帖子上执行此操作,但我希望能够将精选图片保留在主页上。

这可能吗?

修改

Pastebin File根据要求。

根据Chris Herberts的回答,我会将他的代码添加到我的single.php文件中找到的代码中:

    <?php if(has_post_thumbnail()) {
        echo '<figure class="featured-thumbnail"><span class="img-wrap">'; the_post_thumbnail(); echo '</span></figure>';
        }
      ?>
    <?php } else { ?>
      <?php if(has_post_thumbnail()) {
        echo '<figure class="featured-thumbnail large"><span class="img-wrap"><span class="f-thumb-wrap">'; the_post_thumbnail('post-thumbnail-xl'); echo '</span></span></figure>';
        }
      ?>
    <?php } ?> 

2 个答案:

答案 0 :(得分:7)

另一种不依赖于它们的方法是使用Custom Field

您可以为要隐藏特色图像的帖子设置自定义字段 - 在下图中我分别使用“hide_featured_image”和“yes”作为键和值。

enter image description here

然后,当调用调用函数显示特色图像时,您将检查“hide_featured_image”字段是否设置为“yes”。这是一个例子:

$shouldHideFeaturedImage = get_post_meta($post->ID, 'hide_featured_image', true);

if ( $shouldHideFeaturedImage != 'yes' ) {
 if ( has_post_thumbnail() ) {
    the_post_thumbnail('medium'); 
    } 
}

答案 1 :(得分:2)

如果所有这些帖子属于同一类别,您可以执行以下操作。

在你的主题文件中,在single.php文件下应该有类似的东西:

if ( has_post_thumbnail() ) {
the_post_thumbnail('medium'); 
} 

将其更改为:

if ( !in_category( array( 'category1', 'category2', 'etc' ) )) {
 if ( has_post_thumbnail() ) {
    the_post_thumbnail('medium'); 
    } 
}