I’m trying to use TimThumb to display image on my blog
<?php the_title(); ?>'><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo catch_that_image() ?>&w=290&h=160
the above is the code I use
The problem is that the image doesn’t display because the URL come out something like this.
http://myurl.com/wp-content/themes/ThemeName/timthumb.php?src=&w=290&h=160
In which is suppose to be like this for example
http://myurl.com/wp-content/themes/ThemeName/timthumb.php?src=http://myurl.com/wp-content/uploads/i0n1c.png&w=290&h=160
As you can see above is missing the part from src= and that missing part is this code <?php echo catch_that_image() ?> I’ve tested this code separately and it works just fine but when I combine them together then it doesn’t display it properly?
Is there something I have to add to make it works?
UPDATE:
Here is the function I use to grab the image
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 = "/images/default.jpg";
}
return $first_img;
}
and here is the code to call the URL path for the image.
<?php echo catch_that_image() ?>
That code should output the variable, so you did it in another context, where the value is properly set.
Update:
have you checked the generated source code? You have exta backticks here: