我将“product image.php”复制到我的主题文件夹中,以便稍微更改HTML输出,因此wc_get_gallery_image_html
我创建了我的函数并在那里更改了输出。
这是原件function
这是修改后的一个:
function my_custom_get_gallery_image_html( $attachment_id, $main_image = false ) {
$flexslider = (bool) apply_filters( \'woocommerce_single_product_flexslider_enabled\', get_theme_support( \'wc-product-gallery-slider\' ) );
$gallery_thumbnail = wc_get_image_size( \'gallery_thumbnail\' );
$thumbnail_size = apply_filters( \'woocommerce_gallery_thumbnail_size\', array( $gallery_thumbnail[\'width\'], $gallery_thumbnail[\'height\'] ) );
$image_size = apply_filters( \'woocommerce_gallery_image_size\', $flexslider || $main_image ? \'woocommerce_single\' : $thumbnail_size );
$full_size = apply_filters( \'woocommerce_gallery_full_size\', apply_filters( \'woocommerce_product_thumbnails_large_size\', \'full\' ) );
$thumbnail_src = wp_get_attachment_image_src( $attachment_id, $thumbnail_size );
$full_src = wp_get_attachment_image_src( $attachment_id, $full_size );
$image = wp_get_attachment_image(
$attachment_id,
$image_size,
false,
apply_filters(
\'woocommerce_gallery_image_html_attachment_image_params\',
array(
\'title\' => get_post_field( \'post_title\', $attachment_id ),
\'data-caption\' => get_post_field( \'post_excerpt\', $attachment_id ),
\'data-src\' => $full_src[0],
\'data-large_image\' => $full_src[0],
\'data-large_image_width\' => $full_src[1],
\'data-large_image_height\' => $full_src[2],
\'class\' => $main_image ? \'wp-post-image\' : \'\',
),
$attachment_id,
$image_size,
$main_image
)
);
return \'<div style="background-image:url(\' . esc_url( $full_src[0] ) . \');" data-thumb="\' . esc_url( $thumbnail_src[0] ) . \'" class="woocommerce-product-gallery__image"><a href="\' . esc_url( $full_src[0] ) . \'"></a></div>\';
}
我尝试使用背景图像而不是滑块内的图像,但它仅在第一张幻灯片上加载样式。
顺便说一句,我添加了此部分style="background-image:url(\' . esc_url( $full_src[0] ) . \');"