缩略图的强制大小

I'm trying to put constant image size for post thumbnail in my site. (no matter whats the size of the original image, the image should scale for the constant size). I try this:

<?php if (has_post_thumbnail())  the_post_thumbnail(array(400, 200)); ?>

But then I got this in my site:

<img width="356" height="200" src="http://localhost/mida/wp-content/uploads/2015/07/תמוננ-מ.jpg" class="attachment-400x200 wp-post-image" alt="תמוננ מ">

The width and height are different then what I put.

Thanks in advance!

Why don't you just use CSS? Find the lass that is used on the thumbnails (with yourbrowsers developer tool) and apply the desired size to that class:

.the_thumbnail_class img {
     width: 400px;
     height: 200px;
}

(note: that class name is only a guess)

however, keep in mind that images that don't have a width/heigth proportion of 2:1 will be distorted that way, so it's better so write this:

.the_thumbnail_class img {
     height: 200px;
     width: auto;
}

that way they will all have the same height, the width will adust automatically, keeping the proportions intact.

First set the thumbnail details in functions.php

under add_theme_support( 'post-thumbnails' );

add add_image_size('custom-thumb', 400, 200, true);

Then in your template code you can call like this

echo the_post_thumbnail('custom-thumb');