Wordpress:如何缩放大图像宽度?

时间:2011-07-16 19:56:18

标签: php image wordpress

大尺寸图片打破了我的wordpress主题布局(超出了帖子的宽度)。我注意到Twenty Ten主题很好地缩放了大尺寸图像的宽度(通过减小宽度和高度)。我想做同样的事情,我该怎么做?

3 个答案:

答案 0 :(得分:1)

您需要将此添加到functions.php

add_theme_support( 'post-thumbnails' );

然后你在帖子中使用较小的图像,如:

the_post_thumbnail().

默认大小为50/50,但您可以更改或添加更多尺寸:

更改您的默认尺寸

set_post_thumbnail_size();

并添加尺寸

add_image_size( $name, $width, $height, $crop ); 

然后Wordpress会自动创建不同大小的图像的多个版本。

在以后的版本中,已经有3种尺寸,缩略图,中型和大型,正在为您创建。要使用add_image_size添加这些或任何大小,您只需执行以下操作:

get_the_post_thumbnail($post->ID, 'medium');        // to use the medium size, replace medium with whatever size.

要使用缩略图,您显然不会将图像插入帖子中,而是将其插入主题中。

答案 1 :(得分:0)

我发现this post提供了一种直接的scale() - 方法,可用于执行此操作。

但是我会在完成图片上传(在你的WordPress后端)并将缩略图保存在某个地方时这样做。

此外,WordPress应该可以执行此操作out of the box

答案 2 :(得分:0)

在样式表中尝试类似:

img.size-large {max-width:960px !important}

或者,如果你想强制特定的宽度:

img.size-large {width:960px !important; height:auto !important}
相关问题