Created
November 24, 2012 04:26
-
-
Save steve21124/4138344 to your computer and use it in GitHub Desktop.
index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (has_post_thumbnail()) { | |
$imgsrc = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'medium'); | |
} elseif ($postimages = get_children("post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=0")) { | |
foreach($postimages as $postimage) { | |
$imgsrc = wp_get_attachment_image_src($postimage->ID, 'medium'); | |
} | |
} elseif (preg_match('/<img [^>]*src=["|\']([^"|\'] )/i', get_the_content(), $match) != FALSE) { | |
$imgsrc[0] = $match[1]; | |
} else { | |
$imgsrc[0] = get_template_directory_uri() . '/img/blank.gif'; | |
$imgsrc[1] = '200'; | |
$imgsrc[2] = '200'; | |
} | |
?> | |
<img src="<?php echo $imgsrc[0]; ?>" alt="<?php the_title_attribute(); ?>" style="width:200px; height:<?php echo (200/$imgsrc[1]*$imgsrc[2]); ?>px" /> | |
<?php unset($imgsrc); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment