首页 > 解决方案 > 如何禁用 woocommerce 画廊的产品图片缩略图?

问题描述

我在 woocommerce 产品库的滑块上工作,我不需要/使用生成的缩略图,因为我使用“点”进行导航,我想隐藏/卸载 woocommerce 库生成的缩略图。

首先,我把它放在我的主题functions.php文件中:

remove_theme_support( 'wc-product-gallery-slider' );

实际上,我只是在我的 css 文件中添加了“display:none” ,然后为product-thumbnails.php制作了这个:

// Note: `wc_get_gallery_image_html` was added in WC 3.3.2 and did not exist prior. This check protects against theme overrides being used on older versions of WC.
if ( ! function_exists( 'wc_get_gallery_image_html' ) ) {
    return;
}

global $post, $product;

$attachment_ids = $product->get_gallery_image_ids();

if ( $attachment_ids && $product->get_image_id() ) { ?>

<div class="slider product-responsive-thumbnail" id="product_thumbnail_<?php echo esc_attr( $post->ID ); ?>">
    <?php foreach ( $attachment_ids as $attachment_id ) { ?>
        <div class="thumbnail-wrapper">
        <?php echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', wc_get_gallery_image_html( $attachment_id ), $attachment_id ); // phpcs:disable WordPress.XSS.EscapeOutput.OutputNotEscaped ?>
        </div>
    <?php
    } ?>
</div>
<?php
}
?>

我想完全禁用缩略图的生成及其显示以优化我的页面的加载!

我知道我可以完全删除文件“produtc-thumbnails.php”的内容,但这是一种有点原始的方法,我想知道这是否可以用另一种不那么原始的方法

标签: phpwordpresswoocommerce

解决方案


正如@7uc1f3r向我建议的那样,

第一个简单的解决方案。woocommerce-general.css文件中的掩码如下:

.woocommerce div.product div.images .flex-control-thumbs {
    overflow: hidden;
    zoom: 1;
    margin: 0;
    padding:0;
    display:none; /* this hide the thumbnails */
}

第二种解决方案,在product-thumbnails.php中输入“ false ”

if ( ! function_exists( 'wc_get_gallery_image_html' ) ) {
    return;
}

global $post, $product;

$attachment_ids = false; // This disable the thumbnails

瞧,现在由您来选择要保留的方法。


推荐阅读