【发布时间】:2010-04-06 10:33:07
【问题描述】:
有人知道是否有办法在帖子上设置图片上传字段,以便我可以为该帖子上传特定图片。
谢谢
【问题讨论】:
标签: wordpress
有人知道是否有办法在帖子上设置图片上传字段,以便我可以为该帖子上传特定图片。
谢谢
【问题讨论】:
标签: wordpress
目前不可能(已经照顾了几个月但没有运气)。
您是否尝试将该图像显示为缩略图(同时为作者提供方便)?
最好的方法是自动检测帖子中的第一张图片。用户无需处理自定义字段或 URL:
// Get URL of first image in a post
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
// no image found display default image instead
if(empty($first_img)){
$first_img = "/images/default.jpg";
}
return $first_img;
}
// With TimThumb
<img src="/thumb.php?src=<?php echo catch_that_image() ?>&w=200&zc=1&q=200" alt="<?php the_title(); ?>"/>
在这里找到它:http://snipplr.com/view/23968/wordpress--get-first-image-of-post-without-custom-fields/
如果这不是您想要的,请提供更多详细信息,我们会努力寻找解决方案。
:)
【讨论】:
我使用的解决方案是Flutter 模块,它让我可以创建自定义内容类型。
【讨论】:
这不是一个理想的解决方案,但我目前只是使用一个名为“缩略图”的自定义字段并将上传图像的位置放在那里。然后,当我在某处显示帖子详细信息时,我使用自定义字段中的值作为 <img src=""> 值。
首先要上传图片,我只需使用编辑器中的普通图片上传工具,然后在我写帖子时将上传的名称复制到自定义字段中。
不是很优雅,但很有效。
【讨论】: