Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_first_image() {
- global $post;
- $PostID = $post->ID;
- $all_images =& get_children('post_type=attachment&post_mime_type=image&post_parent=' . $PostID );
- if($all_images) {
- $arr_of_all_images = array_keys($all_images);
- // Get the first image attachment from post
- $firstImage = $arr_of_all_images[0];
- // Get the thumbnail url for the attachment
- // If you want the full-size image instead of the thumbnail, use wp_get_attachment_url() instead of wp_get_attachment_thumb_url().
- $thumb_url = wp_get_attachment_thumb_url($firstImage);
- echo $thumb_url;
- }
- }
Add Comment
Please, Sign In to add comment