我正在開發自己的wordpress主題。我在檢索帖子圖片時遇到了問題。WordPress的圖像檢索問題3.5.1
我用下面的代碼:
if ($images = get_children(array(
'post_parent' => $postid,
'post_type' => 'attachment',
'numberposts' => '1',
'post_mime_type' => 'image',)))
foreach($images as $image) {
$thumbnail=wp_get_attachment_image_src($image->ID, $size);
?>
<?php echo get_image_path($thumbnail[0]); ?>
}
else ....// retrieve a default error image
此代碼工作正常,如果我上傳新的圖片,我將其固定到職位,但如果我附上從媒體拍攝的舊形象我失敗圖書館。
我找不出問題在哪裏。根據Wordpress的函數引用,get_children()和get_image_path()不會被棄用。
我使用WordPress的最新avaible verison(3.5.1)
連接到有問題('$ postid')後那些老的圖像?還是他們不附加/附加到其他職位? – brasofilo 2013-02-14 23:18:38
我發現,如果我從媒體庫中選擇圖像並放入帖子內,則不會將其視爲附加到帖子。 所以我想知道如何讓圖像插入帖子(附加或不附)。 – 2013-02-15 09:28:39
不可能不查詢所有帖子並檢查'post_content'內的附件URL ...... – brasofilo 2013-02-15 09:30:51