我正在将Woocommerce用于1800多个产品电子商店。 Woocommerce附带一个内置的PrettyPhoto灯箱插件。默认情况下,当您单击以缩放灯箱中的图像时,它会加载原始Wordpress图像大小。
Woocommerce在模板'product-image.php'中调用此原始图像。我可以修改那个。变量$ image_link调用原始大小。我想打电话给我已经制作的自定义尺寸。我只是不知道怎么称呼它,我在文档,论坛和网站上找了一天但找不到它。
我需要修改$ image_link,以便调用我的自定义图像大小(我通过add_image_size添加)。但是怎么样?我知道这是Wordpress的基础知识,但我无法完成它......
我的网站示例(点击放大,它会显示1600px宽图像的缩小图像,但我想要一个较小的图像):http://www.affichesmarci.com/shop/the-railys-cycling-act/
<?php
if ( has_post_thumbnail() ) {
$image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ) );
$image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) );
$image_link = wp_get_attachment_url( get_post_thumbnail_id() );
$attachment_count = count( $product->get_gallery_attachment_ids() );
if ( $attachment_count > 0 ) {
$gallery = '[product-gallery]';
} else {
$gallery = '';
}
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<a href="%s" itemprop="image" class="bigbox woocommerce-main-image zoom" title="%s" rel="prettyPhoto' . $gallery . '">%s</a>', $image_link, $image_title, $image ), $post->ID );
} else {
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="Placeholder" class="bigbox" />', woocommerce_placeholder_img_src() ), $post->ID );
}
?>
<?php do_action( 'woocommerce_product_thumbnails' ); ?>
答案 0 :(得分:5)
我自己找到了解决方案。
调用全尺寸图像的原始变量。
$image_link = wp_get_attachment_url( get_post_thumbnail_id() );
调用自定义尺寸“缩放”的新变量。
$image_link = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'zoom' );
答案 1 :(得分:0)
如果您已在功能中设置“add_image_size”,我认为您可以轻松编辑
$image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ) );
到
$image = get_the_post_thumbnail( $post->ID, apply_filters( 'your_thumbnail_name', 'shop_single' ) );
您还可以使用WP的默认大小,即“缩略图”,“中等”,“大”和“完整”
答案 2 :(得分:0)
好的,添加大尺寸而不是完整
$image_link = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large');
现在将$image_link
更改为$image_link[0]
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s" rel="prettyPhoto' . $gallery . '">%s</a>', $image_link[0], $image_title, $image ), $post->ID );
感谢您的想法:)