Organizational Research By

Surprising Reserch Topic

how do you set only the image width of a wordpress thumbnail


how do you set only the image width of a wordpress thumbnail  using -'wordpress'

I am trying to set the width of a post thumbnail using

the_post_thumbnail().

The width of the image needs to be 210px but the height is not meant to be fixed as all the images will be different sizes. I have tried

the_post_thumbnail(array(210,0))

but this does not work. Any ideas?

Thanks
    

asked Oct 23, 2015 by sumit_jaiswalmca
0 votes
0 views



Related Hot Questions

2 Answers

0 votes

Add this inside your functions.php

if ( function_exists( 'add_image_size' ) ) { 
add_image_size( 'category-thumb', 210, 9999 ); //210 pixels wide (and unlimited height)

}

Use it inside your theme's template files


For default thumbnail add this inside your functions.php

if ( function_exists( 'add_theme_support' ) ) {
    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 150, 9999 ); // default Post Thumbnail dimensions   
}

Reference: Here.

answered Oct 23, 2015 by sandeep bhadauria
0 votes

Open your themes functions.php file and add your image size:

Example:

add_image_size('slider', 525, 339, true);

Breakdown of the code:

  • 'slider'= The name of the new image size (use this when adding the new image size to your template file).
  • 525 = The image width
  • 339 = The image height
  • true = The image will be cropped to the exact dimensions listed.

Usage: Use a current template (index.php, single.php, etc.), or create your own. Place this inside the loop (usually just after the_title();) :

the_post_thumbnail('slider');

Now when you add a page or post that uses the template you added the code above, use the featured image option to upload an image. It will output to the size you've created.

Note: This will only apply to newly uploaded images.

answered Oct 23, 2015 by mannumits1

...