.firstly add this function in
functions.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 =
bloginfo(template_directory)."/images/download.jpg"; // this image used when //no image found
}
return $first_img;
}
Now this used where u want to add
image .
if (
get_the_post_thumbnail($post_id) != '' ) {
$large_image_url=wp_get_attachment_image_src(get_post_thumbnail_id(),'large');
echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
echo '<img src="';
echo $large_image_url[0];
echo '" alt=""
style="width:281px;height:154px;"/>';
echo '</a>';
} else {
echo '<a href="'; the_permalink();
echo '" class="thumbnail-wrapper">';
echo '<img src="';
echo catch_that_image();
echo '" alt=""
style="width:281px;height:154px;"/>';
echo '</a>';
}
OR
if (
get_the_post_thumbnail($post_id) != '' ) {
echo '<a href="'; the_permalink(); echo '"
class="thumbnail-wrapper">';
the_post_thumbnail();
echo '</a>';
} else {
echo '<a href="'; the_permalink();
echo '" class="thumbnail-wrapper">';
echo '<img src="';
echo catch_that_image();
echo '" alt="" />';
echo '</a>';
}
1 comments:
Goood and nice post !!!!
EmoticonEmoticon