我想将图库缩略图的缩略图大小更改为最大。 60x60px。无需裁剪。
我在WooCommerce文档中发现了以下钩子:
add_filter( 'woocommerce_gallery_thumbnail_size', function( $size ) {
return array('width' => 60, 'height' => 60, 'crop' => 0, );
} );
但是似乎crop参数没有效果?! WordPress也会忽略此大小,并在图库导航中始终显示WordPress本身的150x150px版本。即使在使用插件重新生成缩略图大小之后。 服务器上有60x60版本。但是WooCommerce并未使用它,而是裁剪掉了。
我还使用此代码向主题添加WooCommerce支持:
function mytheme_add_woocommerce_support() {
add_theme_support( 'woocommerce', array(
'thumbnail_image_width' => 240,
'single_image_width' => 450,
'gallery_thumbnail_image_width' => 60,
) );
add_theme_support( 'wc-product-gallery-slider' );
}
add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );
当我删除它时,WooCommerce缩略图的大小将被完全忽略。
我做错了什么吗? 它适用于以下其他图像尺寸:
add_filter( 'woocommerce_get_image_size_thumbnail', function( $size ) {
return array('width' => 240, 'height' => 240, 'crop' => 0, );
} );
add_filter( 'woocommerce_get_image_size_single', function( $size ) {
return array('width' => 450, 'height' => 450, 'crop' => 0, );
} );
这些图像最大宽度和高度,并且不会裁剪。 但是图库缩略图版本始终会被裁剪。
答案 0 :(得分:0)
我找到了一个解决方案,但我猜这是过滤器中的错误名称。
我使用的名字(woocommerce_gallery_thumbnail_size
)是从文档复制而来的,但他的名字似乎是正确的版本:woocommerce_get_image_size_gallery_thumbnail
从这里后退:https://theme.co/forum/t/woocommerce-product-gallery-thumbnails-cropped/47367/2
这是他们的代码:
// change woocommerce thumbnail image size
add_filter( 'woocommerce_get_image_size_gallery_thumbnail', 'override_woocommerce_image_size_gallery_thumbnail' );
function override_woocommerce_image_size_gallery_thumbnail( $size ) {
// Gallery thumbnails: proportional, max width 200px
return array(
'width' => 60,
'height' => 60,
'crop' => 0,
);
}
不幸的是,图库滑块导航窗台使用图像的150x150版本。但这不是这个问题的重点。