lucasw Posted June 7, 2010 Share Posted June 7, 2010 Below is my current code, which I'm using in wordpress. Here's what I'd like to do and can't figure out: - Instead of displaying /images/default.jpg if there is no image found I would like nothing to be displayed. Currently I get a empty box. - Instead of running the below code first I would like <?php the_post_thumbnail(); ?> to be checked for an image, and if it is blank then the below code goes into action Any help? 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; } Quote Link to comment https://forums.phpfreaks.com/topic/204130-image-script-mod-check-for-image-grab-image/ Share on other sites More sharing options...
trq Posted June 7, 2010 Share Posted June 7, 2010 There is an if statement in the code provided that is responsible for defining a default. Quote Link to comment https://forums.phpfreaks.com/topic/204130-image-script-mod-check-for-image-grab-image/#findComment-1069178 Share on other sites More sharing options...
lucasw Posted June 7, 2010 Author Share Posted June 7, 2010 I know. But how do I make it appear blank is the question? Quote Link to comment https://forums.phpfreaks.com/topic/204130-image-script-mod-check-for-image-grab-image/#findComment-1069210 Share on other sites More sharing options...
trq Posted June 7, 2010 Share Posted June 7, 2010 Remove the if statement, then when calling the function you could use something like.... if ($img = catch_that_image()) { echo "<img src='$img' />"; } Quote Link to comment https://forums.phpfreaks.com/topic/204130-image-script-mod-check-for-image-grab-image/#findComment-1069219 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.