WE ARE NATIONAL OF MYANMAR! WELCOME!

Wednesday 23 January 2013

how to get thumbnail image in the post on wordpress

First of all , you must open function.php in your theme directory. And then put  this codes in function.php .

<?php
add_theme_support( 'post-thumbnails' );
add_theme_support( 'post-thumbnails', array( 'post' ) );          // Posts only
add_theme_support( 'post-thumbnails', array( 'page' ) );          // Pages only
add_theme_support( 'post-thumbnails', array( 'post', 'movie' ) ); // Posts and Movies ?>

After that you can use thumbnail image by  code . you can add this code where you want to show image in template .

 the_post_thumbnail();                  // without parameter -> 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

you must only one code line . Meaning that  .....

if you need thumbnail size , you must use  the_post_thumbnail('thumbnail');
if you need medium size , you must use  the_post_thumbnail('medium');

if you want to define custom image size  . . .

use this code ...... where you want to show image in the template ...

<?php if ( function_exists( 'add_theme_support' ) ) {
  add_theme_support( 'post-thumbnails' );
        set_post_thumbnail_size( 300, 300,true );
}?>


Set the default Post Thumnail size by resizing the image proportionally (that is, without distorting it):

set_post_thumbnail_size( 50, 50 ); // 50 pixels wide by 50 pixels tall, resize mode

Set the default Post Thumnail size by cropping the image (either from the sides, or from the top and bottom):

set_post_thumbnail_size( 50, 50, true ); // 50 pixels wide by 50 pixels tall, crop mode.


reference : wordpress.org


1 comment: