Skip to content

Instantly share code, notes, and snippets.

@adis-io
Created September 18, 2012 17:39
Show Gist options
  • Save adis-io/3744541 to your computer and use it in GitHub Desktop.
Save adis-io/3744541 to your computer and use it in GitHub Desktop.
thumb
function has_post_images($id) {
$files = get_children('post_parent='.$id.'&post_type=attachment&post_mime_type=image&order=desc');
return $files;
}
function get_the_post_image($id, $width, $height) {
if ( has_post_images($id) ) :
$files = has_post_images($id);
$keys = array_reverse(array_keys($files));
$j = 0;
$num = $keys[$j];
$image = wp_get_attachment_image($num, 'large', true);
$imagepieces = explode('"', $image);
$imagepath = $imagepieces[1];
$main = wp_get_attachment_url($num);
$template=get_template_directory();
$the_title=get_the_title();
print "<img src='$main' alt='$the_title' height = '$height' width = '$width' class='shadow-190' />";
endif;
};
<div class="featured-thumbnail news-photo">
<a href="<?php the_permalink(); ?>">
<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) {
echo get_the_post_thumbnail($post->ID,array(190, 139));
} elseif ( has_post_images($post->ID) ) {
echo get_the_post_image($post->ID,190,139);
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/images/placeholder.jpg" width="190" height="139" alt="<?php the_title(); ?>" />
<?php } ?>
<!-- <img src="http://lorempixel.com/190/120/city/<?php echo rand(1,5) + rand(1,5) ?>" class="shadow-190" width="190" height="110"> -->
</a>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment