/ Published in: PHP

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // ADD THIS IN THE functions.php FILE function catch_that_image() { global $post, $posts; $first_img = ''; $first_img = $matches [1] [0]; $first_img = "/uploads/default.jpg"; } return $first_img; }?> --------------------------------------------------------------------- <?php // ADD THIS IN THE DESIRED TEMPLATE FILE $content = $post->post_content; $searchimages = '~<img [^>]* />~'; /*Run preg_match_all to grab all the images and save the results in $pics*/ // Check to see if we have at least 1 image if ( $iNumberOfPics > 0 ) { ?> <!-- GRAB THE IMAGE AND USE WHATEVER HTML YOU LIKE --> <img src="<?php echo catch_that_image() ?>" alt="<?php the_title(); ?>" /></a> <?php } ?>
Comments
