Created
February 27, 2013 04:14
-
-
Save omurphy27/5045011 to your computer and use it in GitHub Desktop.
Wordpress PHP Featured Image
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 | |
// Wordpress PHP Featured Images Overview | |
// Next, I should add support for featured images | |
// http://codex.wordpress.org/Post_Thumbnails | |
// In order to use such images, I need to add a few things to the functions.php file | |
///First, I have to add | |
add_theme_support( 'post-thumbnails' ); | |
// just to enable featured images | |
// If I just want to show the images in their full size, then I do like so: | |
the_post_thumbnail( 'full', array('class' => 'gameimage') ); | |
//To add multiple featured image sizes I can do like this: http://codex.wordpress.org/Function_Reference/add_image_size | |
// I would add as many sizes as I wanted to my functions file: | |
add_image_size( 'main-category-thumb', 280, 280, true ); | |
add_image_size( 'small-category-thumb', 180, 180, true ); | |
add_image_size( 'single-page-thumb', 180, 180, true ); | |
// Here's how I check to see if a post has a thumbnail (if it does I post said thumbnail, if not then I post a default image or can post nothing) | |
if ( has_post_thumbnail() ) { | |
the_post_thumbnail('main-category-thumb' ); | |
} else { ?> | |
<img src="<?php bloginfo('template_directory'); ?>/images/placeholder-android-image.jpg" /> | |
} | |
// be sure to paste the above in the loop | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment