Created
February 5, 2014 13:32
-
-
Save PabloVallejo/8823650 to your computer and use it in GitHub Desktop.
Post_Model::thumb
This file contains hidden or 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 | |
/** | |
* 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