2012-11-20 27 views
0

我使用自定義字段photo上傳圖像。在前臺,我得到它的URL與此代碼:WordPress的:使用the_post_thumbnail()自定義字段圖像

$imgid=get_post_meta($post->ID, 'photo', true); 
$img=wp_get_attachment_image_src($imgid); 
$imgurl=$img[0]; 

現在我想表明它使用the_post_thumbnail的標準WP尺寸(縮略圖,中...)()。

我已經嘗試了一些解決方案不起作用:

the_post_thumbnail('medium', array('src' => $imgurl)); 

the_post_thumbnail('medium', $img); 

任何想法?

回答

2

只是通過大小爲wp_get_attachment_image_src()第二個參數,就像這樣:

$imgid = get_post_meta($post->ID, 'photo', true); 
$img = wp_get_attachment_image_src($imgid, 'thumbnail'); 
$imgurl = $img[0]; 
+1

是是是!有用!非常非常感謝nikola! :) –

相關問題