tags:

views:

44

answers:

3

Does anybody know if there is a way of having an image upload field on a post so I can upload a specific image for that post.

Thanks

+1  A: 

It's not currently possible (have been looking after it for months with no luck).

Are you trying to display that image as a thumbnail (while keeping it easy for the authors)?

The nicest approach is auto-detecting the first image in the post. Users don't need to deal with custom fields nor URLs:

// 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(); ?>"/>

Found it here: http://snipplr.com/view/23968/wordpress--get-first-image-of-post-without-custom-fields/

If that's not what you were looking for please give more details and we'll try to find a solution.

:)

XaviEsteve
In the end I used the Flutter module to create an image field. Works for me!
Probocop
A: 

It's not an ideal solution but I'm currently just using a custom field called "thumbnail" and putting the location of an uploaded image in there. Then, when I display the post details somewhere I use the value from the custom field as the <img src=""> value.

To upload the image in the first place I just use the normal image upload tool in the editor and copy the uploaded name into the custom field as I'm writing the post.

Not very elegant but it works.

Steve Claridge
A: 

The solution I used was the Flutter module, which let me create custom content types.

Probocop