Php 如果上传的图片尺寸较小,我如何强制WordPress缩略图拉伸以适应?

Php 如果上传的图片尺寸较小,我如何强制WordPress缩略图拉伸以适应?,php,wordpress,Php,Wordpress,我网站上的用户上传的图像小于我的WordPress主题的基本缩略图尺寸。我如何强制这些类型的图像垂直或水平拉伸,以便没有空白 我的wp admin>settings>media>缩略图大小设置为124px 156px。上传的图像60px 190px会破坏网站布局。www.sharehouse.co是测试站点。 下面的代码需要修改 <div class="post-left"> <a href="<?php the_permalink(); ?>" <?

我网站上的用户上传的图像小于我的WordPress主题的基本缩略图尺寸。我如何强制这些类型的图像垂直或水平拉伸,以便没有空白

我的
wp admin>settings>media>缩略图大小设置为
124px 156px
。上传的图像
60px 190px
会破坏网站布局。www.sharehouse.co是测试站点。 下面的代码需要修改

<div class="post-left">
    <a href="<?php the_permalink(); ?>" <?php if ((get_option('cp_ad_image_preview') == 'yes') && (cp_get_image_url_raw($post->ID, 'large', 1) == true)) { ?>class="preview" rel="<?php echo cp_get_image_url_raw($post->ID, 'large', 1); ?>" <?php } ?>><?php if(get_post_meta($post->ID, 'images', true)) cp_single_image_legacy($post->ID, get_option('thumbnail_size_w'), get_option('thumbnail_size_h'), 'preview'); else cp_get_image_url_feat($post->ID, 'thumbnail', 'preview', 1); ?></a>                
</div>


因此,您需要做的第一件事是从WordPress创建的
img
HTML中去掉硬编码的宽度和高度属性。它认为你应该拥有这些维度,并迫使你使用它们

摘自:

那就是CSS

.attachment img {
  width: 100%; /* scale to width of container, or whatever you want */
}

哇!快速响应!那么,我是否要将您的上述代码添加到我问题中的代码中?我在哪里添加它?我发现代码是用firebug编写的——我不是一个程序员。第一部分可能会出现在
functions.php
文件中,尽管这可能取决于网站的设置方式。很可能是去那里了。CSS进入
style.CSS
文件。不过,提供的CSS将使所有图像都适合其容器,因此请确保根据您的需要对其进行更改。
.attachment img {
  width: 100%; /* scale to width of container, or whatever you want */
}