in ,

Enable Featured Images In Your WordPress Theme

Featured images is an image that is chosen as the representative image for Posts, Pages or Custom Post Types. The display of this image is up to the theme. This is especially useful for “magazine-style” themes where each post has an image.

Enabling Support for Featured Images

To do that you need to go to your ‘function.php‘ file within your theme folder (wp-content/themes/theme-name/).
To add thumbnail support for all post types, append this command somewhere after the opening <php:

[php]add_theme_support(‘post-thumbnails’);[/php]

Alternatively, you can enable thumbnails for just posts:

[php]add_theme_support(‘post-thumbnails’, array(‘post’));[/php]

or just pages:

[php]add_theme_support(‘post-thumbnails’, array(‘page’));[/php]

Setting a Post Thumbnail

featured_image_metaboxIf your theme was successful in adding support for Post Thumbnails the “Featured Image” metabox will be visible on the on the Edit Post and Edit Page screens. If it isn’t, make sure “Featured Image” is enabled in the screen options on the top right.

Setting Thumbnail Sizes

The default image sizes of WordPress are “thumbnail” (and its “thumb” alias), “medium”, “large” and “full” (the image you uploaded). These image sizes can be configured in the WordPress Administration Media panel under Settings > Media. If your theme enables Post Thumbnails then “post-thumbnail” is also available and this is the default when using Post Thumbnails. This is how you use these default sizes with the_post_thumbnail():

[php]

// without parameter -> Post Thumbnail (as set by theme using set_post_thumbnail_size())
the_post_thumbnail();

the_post_thumbnail(‘thumbnail’); // Thumbnail (default 150px x 150px max)
the_post_thumbnail(‘medium’); // Medium resolution (default 300px x 300px max)
the_post_thumbnail(‘large’); // Large resolution (default 640px x 640px max)
the_post_thumbnail(‘full’); // Original image resolution (unmodified)

the_post_thumbnail( array(100,100) ); // Other resolutions

[/php]

Displaying Featured Images in the Theme

[php]// check if the post has a Post Thumbnail assigned to it.
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
the_content();[/php]

More information about enable featured images in wordpress please visit here.

What do you think?

Written by Sopheap

The goal of me is sharing new ideas, inspiration art, fresh and useful resource, covering web design and development, graphic design, advertising, mobile development and life style.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Mega Menu

WordPress menu plugin best collection

Create a post apocalyptic scene in Photoshop

Awesome Photoshop Manipulation Collection