Skip to content

Instantly share code, notes, and snippets.

@turboclaw
Created December 18, 2012 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turboclaw/4324786 to your computer and use it in GitHub Desktop.
Save turboclaw/4324786 to your computer and use it in GitHub Desktop.
This example will look for the first image in a post, and, if there is one, will display a 75 x 75 pixel thumbnail of it. You can pass an array with width and height, or a size keyword (see here: http://codex.wordpress.org/Function_Reference/wp_get_attachment_image).
<?php
$images = get_children('post_parent='.$post->ID.'&post_type=attachment&post_mime_type=image&numberposts=1&order=ASC');
if(!empty($images)){
echo wp_get_attachment_image(reset($images)->ID, array(75,75));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment