Created
January 16, 2015 05:42
-
-
Save inc2734/6bc63c8fa27db64ea32a to your computer and use it in GitHub Desktop.
WordPress でサムネイルか、それが無いときのデフォルト画像を出し分けるテンプレートタグ
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 | |
class Hoge { | |
/** | |
* get_the_post_thumbnail | |
* @param string $size | |
* @param array $attributes | |
* @return string | |
*/ | |
public static function get_the_post_thumbnail( $size = 'post-thumbnail', array $attributes = array() ) { | |
if ( has_post_thumbnail() ) { | |
return get_the_post_thumbnail( get_the_ID(), $size, $attributes ); | |
} else { | |
return sprintf( '<img src="%s/path/to/default-thumbnail.jpg" alt="" />', get_template_directory_uri() ); | |
} | |
} | |
/** | |
* the_post_thumbnail | |
* @param string $size | |
* @param array $attributes | |
*/ | |
public static function the_post_thumbnail( $size = 'post-thumbnail', array $attributes = array() ) { | |
echo self::get_the_post_thumbnail( $size, $attributes ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment