/ Published in: PHP

This will find the first image in post and return it as a thumbnail if it exists
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function test_me() { $files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image'); if($files) : $keys = array_reverse(array_keys($files)); $j=0; $num = $keys[$j]; $image=wp_get_attachment_image($num, 'large', false); $imagepieces = explode('"', $image); $imagepath = $imagepieces[1]; $thumb=wp_get_attachment_thumb_url($num); print "<img src='$thumb' class='thumbnail' />"; endif; } <?php test_me(); ?>
Comments
