I am using some code to automatically retrieve the first image from my posts and display it, I am also using timthumb to resize these images into thumbnails. I have got everything setup correctly as the default image shows, but when the code tries to work with a image uploaded through the media uploader to the 'files' folder, the URL doesn't work. This is what is created:
and I get the error message - file not found /cms/files/2009/04/istock_000001757949small.jpg. If I isolate the filepath at the end of the URL the image displays, but the timthumb resizer will not work unless I change the URL to this:
The code to grab the first image is posted below, does anyone know how I could modify this so that it pulls the correct filepath?
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];
if(empty($first_img)){ //Defines a default image
$first_img = "http://news.boatwizardwebsolutions.co.uk/cms/wp-content/themes/bc_features/images/default.jpg";
}
return $first_img;
}
Thanks