Skip to content

Instantly share code, notes, and snippets.

@PabloVallejo
Created February 5, 2014 13:32
Show Gist options
  • Save PabloVallejo/8823650 to your computer and use it in GitHub Desktop.
Save PabloVallejo/8823650 to your computer and use it in GitHub Desktop.
Post_Model::thumb
<?php
/**
* Get the post thumbnail src
*
* <code>
*
* // Print post thumbnail
* <img src="<?php echo Post_Model::thumb(); ?>" />
*
*
* // Specifying the post ID
* <img src="<?php echo Post_Model::thumb( 10 ); ?>" />
*
* </code>
*
* @param { int } Post ID
* @return { str } thumbnail Src
*/
public static function thumb( $post_id = null, $size = '' ) {
global $post;
$fallback = IMAGES_URL . 'home/home-list.jpg';
$post_id = is_numeric( $post_id ) ? $post_id : $post->ID;
if ( ! has_post_thumbnail( $post_id ) )
return;
$attach_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $size );
return has_post_thumbnail( $post_id ) ?
$attach_image[ 0 ] : $fallback;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment