0
A
回答
0
如果你永遠只有一個形象 - 這將是更好的將其設置爲 「特色圖片」,然後:
$image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'your-image-size')
然後
echo $image[0] ;is your link
完整代碼:
<?php if (has_post_thumbnail($post->ID)): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full'); ?>
<a href='<?php echo $image[0]; ?>'> my image link </a>
,如果你不希望使用特色圖片 - 下一個功能將讓你總是第一個圖像中的後
// Get URL of first image in a post
function postimage($echo = true) {
$image = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1,
'order' => 'asc',
'orderby' => 'ID',
'post_mime_type' => 'image',
));
$image_url = ($image) ? wp_get_attachment_url(current($image)->ID) : "No Image";
if($echo)
echo $image_url;
else
return $image_url;
}
,如果你有一個以上的圖像的東西就會變得稍微有點複雜 - 你將有搜索所有附件並遍歷數組。 (改變'numberposts'=> -1,得到所有)
相關問題
- 1. 添加帖子ID作爲類到附件圖像
- 2. wordpresslib將圖像附加到帖子中
- 3. 圖表API中的帖子的附加鏈接
- 4. 添加圖像鏈接
- 5. 添加類圖像鏈接
- 6. 無法在帖子中附加標題和帖子排在android
- 7. 附加鏈接像在谷歌加或鏈接在asp.net或jquery
- 8. 添加Web.config作爲鏈接
- 9. 在javascript中添加鏈接到圖像
- 10. 如何在wordpress主題中添加鏈接並從內容管理的帖子管理該鏈接的網址?
- 11. 添加攝像頭作爲子視圖
- 12. 附加圖標鏈接MuPDF
- 13. 樹視圖 - 爲附加超級鏈接
- 14. 附加鏈接
- 15. 更改/添加圖像標題和ALT內的WordPress帖子
- 16. 在Wordpress自定義帖子類型中修改「添加帖子」鏈接
- 17. 將圖片附加到WordPress帖子
- 18. WordPress的帖子 - 附加圖片
- 19. 添加網頁鏈接作爲圖像的水印
- 20. 向PayPal電子郵件鏈接添加附加變量
- 21. 添加從多個網站WordPress的帖子中的附屬鏈接
- 22. 添加列作爲鏈接在CGridView
- 23. 如何在MFMailComposer消息主體中添加圖像(不作爲附件)
- 24. 如何將圖像視圖添加爲電子郵件附件?
- 25. 在WordPress的帖子中添加rel =「nofollow」的所有鏈接
- 26. css問題 - '帖子鏈接'
- 27. 添加鏈接到flexslider圖像
- 28. 添加鏈接到圖像中bxslider
- 29. OpenCart:如何添加鏈接到圖像
- 30. 添加鏈接到jCarousel圖像
你將永遠只有一個圖像? – 2012-03-30 11:19:28