Wordpress - 图片上传自定义字段?

时间:2010-04-06 10:33:08

标签: wordpress

有人知道是否有办法在帖子上设置图片上传字段,以便我可以上传该帖子的特定图片。

由于

3 个答案:

答案 0 :(得分:1)

目前还不可能(几个月没有运气照顾它)。

您是否尝试将该图像显示为缩略图(同时让作者更容易)?

最好的方法是自动检测帖子中的第一张图片。用户无需处理自定义字段或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/

如果那不是你想要的,请提供更多细节,我们会尽力找到解决方案。

:)

答案 1 :(得分:1)

我使用的解决方案是Flutter模块,它允许我创建自定义内容类型。

答案 2 :(得分:0)

这不是一个理想的解决方案,但我目前只是使用一个名为“缩略图”的自定义字段,并将上传图像的位置放在那里。然后,当我在某处显示帖子详细信息时,我使用自定义字段中的值作为<img src="">值。

要首先上传图片,我只需使用编辑器中的普通图片上传工具,并在我撰写帖子时将上传的名称复制到自定义字段中。

不是很优雅,但它有效。

相关问题