2012-08-09 56 views
0

花了一段時間在這個上,現在幾乎沒有用。在Wordpress循環中縮略圖或預覽

我試圖改變循環,以便它檢查每個文章的特色圖像,如果它發現一個它顯示,而不是被截斷的文章和鏈接。

所以基本上(邏輯)

Check for featured image 

if there is a featured image display the featured image (and nothing else). 

else display a truncated version of the article. 

任何人可以幫助?

回答

1

在這裏,你走了;

<?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) { ?> 

    <?php $img_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(960,960)); ?> 

    <img src="<?php echo $img_src[0]; ?>" alt="My image" /> 

<?php } else { ?> 

     <?php the_excerpt(); ?> 

<?php } ?> 

查看更多信息的代碼中以下內容;

Wordpress Featured images

Wordpress Excerpts

+0

輝煌,非常感謝。 – 2012-08-10 12:40:08

+0

我的榮幸! :) – McNab 2012-08-10 16:48:33