2014-01-10 89 views
1

如果帖子中有精選圖片,我在添加類到帖子摘錄< p>標記時遇到問題。WordPress的:如果有張貼縮略圖,添加類

這是在添加圖像,如果有一個循環位:

<p class="post-excerpt"> 
    <?php 
     if (has_post_thumbnail()) { 
     the_post_thumbnail('full', array('class'=>'featured-image hide-mobile'));   
     } 
    ?> 

    <?php modified_excerpt(); ?> 
</p> 

這工作得很好。所以,從這我想我可以這樣做:

<p class="post-excerpt <?php if (has_post_thumbnail()) { echo "post-with-thumb"; } ?>"> 

但是,唉,沒有。它甚至不輸出任何東西。任何人都可以對此有所瞭解嗎?

感謝

回答

2

試試這個:

<?php 
$thumb = get_the_post_thumbnail(); 
?> 
<p class="post-excerpt<?php echo $thumb != '' ? ' post-with-thumb' : '' ?>"> 
    <?php 
     if ($thumb != '') { 
     the_post_thumbnail('full', array('class'=>'featured-image hide-mobile'));   
     } 
    ?> 
    <?php modified_excerpt(); ?> 
</p> 

與the_post_thumbnail()(見示例部分)根據http://codex.wordpress.org/Function_Reference/has_post_thumbnail可能存在的問題。

相關問題