Return to Snippet

Revision: 35117
at November 2, 2010 23:27 by howardpanton


Initial Code
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(); ?>

Initial URL

                                

Initial Description
This will find the first image in post and return it as a thumbnail if it exists

Initial Title
Find first image in blog post and return it as a thumbnail

Initial Tags
post, wordpress

Initial Language
PHP