在Woocommerce中的product-thumbnails.php中添加图像

时间:2019-06-19 08:21:29

标签: php woocommerce

我正在使用插件高级自定义文件显示产品类别中的其他缩略图。一切正常。但我希望此图像也显示在产品图像库中。怎么做?进阶自订档案图片的程式码:

<?php 
$image = get_field('sheme');
if( !empty($image) ): 
// vars
$url = $image['url'];
$title = $image['title'];
$alt = $image['alt'];
$caption = $image['caption'];

// thumbnail
$size = 'thumbnail';
$thumb = $image['sizes'][ $size ];
$width = $image['sizes'][ $size . '-width' ];
$height = $image['sizes'][ $size . '-height' ];

if( $caption ): ?>
    <div class="wp-caption">
<?php endif; ?> 
        <div class="minipic">
<a href="<?php echo $url; ?>" title="<?php echo $title; ?>"rel="ilightbox[cmsmasters_product_gallery]">
    <img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>"/>
</a>
            </div>          
<?php if( $caption ): ?>
        <p class="wp-caption-text"><?php echo $caption; ?></p>
    </div>
<?php endif; ?>
<?php endif; ?>

product-thumbnails.php的代码 看起来像这样:

<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $product;
$attachment_ids = $product->get_gallery_image_ids();
if ( $attachment_ids && has_post_thumbnail() ) {
echo '<div class="thumbnails cmsmasters_product_thumbs">';

    foreach ( $attachment_ids as $attachment_id ) {
        $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'] ) );
        $main_image        = false;
        $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, 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],
        ) );

        echo '<a href="' . esc_url( $full_src[0] ) . '" 
class="cmsmasters_product_thumb" rel="ilightbox[cmsmasters_product_gallery]">' . $image . '</a>';
    }

echo '</div>';
}

0 个答案:

没有答案