Help displaying first image of a post as thumbnail. :)
-
Hey guys,
Thanks for checking this out, hope you can all help.
I’m currently setting up a new theme that can use post by email,
I have used some php from http://www.wprecipes.com to grab the posts first image and then grab the thumbnail of that image.Now that all works great, but I need to check two things.
If there is no image in the post(only a video for example)I need the script to grab the posts featured image which gets created by video thumbnail plugin.
so the code is below:
<?php
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))
{
$first_img = ” ;
/////////// I THINK I NEED TO PUT SOMETHING IN HERE TO GRAD THE FEATURE IMAGE???? ///////////
}else{$explodepoint = explode(“.”,$first_img);
$count = count($explodepoint);
$size = “-230×200”;
$explodepoint[$count-2]= $explodepoint[$count-2].””.$size;
$thumb_img = implode(“.”,$explodepoint);
echo $thumb_img;
}
}?>
- The topic ‘Help displaying first image of a post as thumbnail. :)’ is closed to new replies.