Skip to content

Instantly share code, notes, and snippets.

@ronipl
Last active January 11, 2019 06:14
Show Gist options
  • Save ronipl/c7bad0d00b8b31fbe0cb9cd517e9ff0b to your computer and use it in GitHub Desktop.
Save ronipl/c7bad0d00b8b31fbe0cb9cd517e9ff0b to your computer and use it in GitHub Desktop.
function get_the_first_image() {
$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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment