2 回答

TA贡献1887条经验 获得超5个赞
重新检查您的主题支持 add_theme_support('post-thumbnails');
只有 woocommerce 你可以试试这个
if (!function_exists('firefog_woocommerce_image_dimensions')) {
function firefog_woocommerce_image_dimensions() {
global $pagenow;
if ( ! isset( $_GET['activated'] ) || $pagenow != 'themes.php' ) {
return;
}
$catalog = array(
'width' => '300', // px
'height' => '300', // px
'crop' => 1 // true
);
$single = array(
'width' => '500', // px
'height' => '500', // px
'crop' => 1 // true
);
$thumbnail = array(
'width' => '100', // px
'height' => '100', // px
'crop' => 1 // true
);
// Image sizes
update_option( 'shop_catalog_image_size', $catalog ); // Product category thumbs
update_option( 'shop_single_image_size', $single ); // Single product image
update_option( 'shop_thumbnail_image_size', $thumbnail ); // Image gallery thumbs
}
}
add_action( 'after_switch_theme', 'firefog_woocommerce_image_dimensions', 1 );
对于默认 WordPress 缩略图
the_post_thumbnail( 'thumbnail' ); // Thumbnail (150 x 150 hard cropped)
the_post_thumbnail( 'medium' ); // Medium resolution (300 x 300 max height 300px)
the_post_thumbnail( 'medium_large' ); // Medium Large (added in WP 4.4) resolution (768 x 0 infinite height)
the_post_thumbnail( 'large' ); // Large resolution (1024 x 1024 max height 1024px)
the_post_thumbnail( 'full' ); // Full resolution (original size uploaded)
如果您需要特定的分辨率
the_post_thumbnail( array(500, 500) ); // 500x500 dimension
Post Thumbnail Linking to Large Image Size您可以通过更改来更改大小large
if ( has_post_thumbnail() ) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
if ( ! empty( $large_image_url[0] ) ) {
printf( '<a href="%1$s" alt="%2$s">%3$s</a>',
esc_url( $large_image_url[0] ),
esc_attr( get_the_title_attribute( 'echo=0' ) ),
get_the_post_thumbnail()
);
}
}
您还可以在主题功能中创建自定义特色图像大小
add_image_size( 'custom-thumb', 300, 300); //Simple widget size
add_image_size( 'sidebar-thumb', 120, 120, true ); // Hard Crop Mode
add_image_size( 'homepage-thumb', 220, 180 ); // Soft Crop Mode
add_image_size( 'singlepost-thumb', 590, 9999 ); // Unlimited Height Mode
以下是如何在主题functions.php文件中创建自定义特色图像大小的示例。
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
add_image_size( 'custom-thumb', 300, 300); // 300 pixels wide
}
在您的 WordPress 主题中显示其他图像大小
the_post_thumbnail( 'your-specified-image-size' ); //Example singlepost-thumb

TA贡献1815条经验 获得超13个赞
这些尺寸包括:
woocommerce_thumbnail
– 用于产品“网格”中的商店页面等地方。
woocommerce_single
– 用于单个产品页面。woocommerce_gallery_thumbnail – 用于
单品页面主图下方切换图库。
woocommerce_single
显示上传的完整产品图像,因此默认情况下始终未裁剪。它默认为 600px 宽度。
woocommerce_gallery_thumbnail
总是方形裁剪,默认为 100×100 像素。这用于在图库中导航图像。
woocommerce_thumbnail
默认为 600px 宽度,方形裁剪,使产品网格看起来整洁。裁剪的纵横比可由店主自定义。
您可以在此处找到有关定义自定义尺寸的上述内容和信息。
- 2 回答
- 0 关注
- 185 浏览
添加回答
举报