Created
October 2, 2012 07:42
-
-
Save aliharis/3817098 to your computer and use it in GitHub Desktop.
Wordpress Theme: Featured Image / Post Thumbnail
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 | |
/** | |
* Featured Image Support for Wodpress Theme | |
* @author Ali Haris (@iharis) (http://gist.github.com/harisdozz) | |
* @since 1349163394 | |
*/ | |
/** | |
* Add the following to theme functions.php to enable the core-function | |
* Enables Featured Image for both Posts and Pages | |
*/ | |
add_theme_support('post-thumbnails'); | |
/** | |
* To enable featured image only to posts | |
*/ | |
add_theme_support('post-thumbnails', array('post')); | |
/** | |
* To enable featured image only to pages | |
*/ | |
add_theme_support('post-thumbnails', array('page')); | |
/** | |
* To resize the thumbnail to 50x50 px, box resize mode | |
*/ | |
set_post_thumbnail_size(50, 50); | |
/** | |
* To resize the thubnail to 50x50 px, hard crop mode | |
*/ | |
set_post_thumbnail_size(50,50, true); | |
/** | |
* To check if the post has thumbnail | |
*/ | |
if ( has_post_thumbnail() ) { | |
// the current post has a thumbnail | |
} else { | |
// the current post lacks a thumbnail | |
} | |
/** | |
* To display the thumbnail | |
*/ | |
the_post_thumbnail(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment