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. 添加类图像链接
- 3. 添加图像链接
- 4. 无法在帖子中附加标题和帖子排在android
- 5. 添加Web.config作为链接
- 6. 如何在wordpress主题中添加链接并从内容管理的帖子管理该链接的网址?
- 7. 树视图 - 为附加超级链接
- 8. 附加链接
- 9. 在Wordpress自定义帖子类型中修改“添加帖子”链接
- 10. WordPress的帖子 - 附加图片
- 11. 将图片附加到WordPress帖子
- 12. 添加网页链接作为图像的水印
- 13. 添加从多个网站WordPress的帖子中的附属链接
- 14. 如何在MFMailComposer消息主体中添加图像(不作为附件)
- 15. 在WordPress的帖子中添加rel =“nofollow”的所有链接
- 16. css问题 - '帖子链接'
- 17. OpenCart:如何添加链接到图像
- 18. 通过javascript添加链接到图像
- 19. 添加自动超链接到图像
- 20. 如何使uicollectionview作为附加图像
- 21. Google附加链接
- 22. 作为子帖子的WordPress图像
- 23. 以附件为单位编程添加Wordpress帖子
- 24. 嗯...“添加为链接”ed图像不显示在运行时
- 25. ExtJS将附加数据添加到表单的帖子中
- 26. 如何添加帖子格式到主题?
- 27. Phpmailer从链接添加PDF附件
- 28. UITableView为图像图标添加标题
- 29. MVC-5 WebGrid添加列标题作为操作链接
- 30. Drupal:添加存档到主要链接作为SubNav
你将永远只有一个图像? – 2012-03-30 11:19:28