我是wordpress的新手,我想使用300 x 283的尺寸,我尝试了the_post_thumbnail(array(\'300,283\'))
但没用,然后我去读了add_image_size
我是这样加的add_image_size( \'homepage-thumb\', 220, 180, true );
, 给我的post\\u缩略图提供了相同的维度,但什么都没有发生,我是否遗漏了什么?如何u我的新添加add_image_size
在里面the_post_thumbnail
how to use the new image size
2 个回复
最合适的回答,由SO网友:cybmeta 整理而成
默认情况下,Wordpress有三种不同的图像大小:全、大、中、缩略图。如果不需要三个以上的图像大小,可以设置默认图像大小的宽度和高度。例如:
add_action( \'after_setup_theme\', \'theme_setup\' );
function theme_setup() {
// Be sure your theme supports post-thumbnails
add_theme_support( \'post-thumbnails\' );
//set thumbnail size to 150 x 150 pixels
set_post_thumbnail_size( 150, 150);
//For the other images size it must be used update_option() function.
//For example, set width to 300 px and height to 200 px for medium size (this is a native image size in Wordpress).
if (get_option(\'medium_size_w\') != 300 ) {
update_option(\'medium_size_w\', 300);
update_option(\'medium_size_h\', 200);
}
}
Note: 可以在Wordpress管理区域中配置每个默认图像大小的尺寸。上述代码将覆盖此配置。如果您需要三种以上的图像大小,您想拥有自己的图像大小,或者不想更改默认图像大小,可以使用添加新的图像大小add_image_size()
功能:
add_action( \'after_setup_theme\', \'theme_setup\' );
function theme_setup() {
// Be sure your theme supports post-thumbnails
add_theme_support( \'post-thumbnails\' );
// the params are \'name of the custom size\', width (px), height (px) and crop (false/true).
add_image_size(\'my-image-size\', 300, 110, true);
}
一旦添加了新的图像大小,或更改了默认大小的宽度/高度,即将发布的图像将具有具有新图像大小的版本。必须重建旧图像。要重建旧图像,您可以再次上载它们或使用插件,例如AJAX Thumbnail Rebuild. 之后,您可以在任何地方使用自定义图像大小,例如:the_post_thumbnail(\'my-image-size\');
SO网友:ThatDudeLarry
查看Codex 再深一点。答案就在那里!
the_post_thumbnail( \'your-custom-size\' );
结束