如何禁用 woocommerce 画廊的产品图像缩略图?

问题描述 投票:0回答:2

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

首先,我将其放入我的主题 functions.php 文件中:

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

实际上,我只是将 "display:none" 放入我的 css 文件中,然后为 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”但这是一个有点原始的方法,我想知道这是否可以使用另一种不太原始的方法

php wordpress woocommerce
2个回答
2
投票

正如@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 */
}

第二种解决方案,将“false”放入product-thumbnails.php

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

global $post, $product;

$attachment_ids = false; // This disable the thumbnails

瞧,现在您可以选择要保留的方法。


0
投票
不幸的是,这两种解决方案都不适用于扁平主题。还有其他人有其他解决方案来隐藏产品缩略图吗?

© www.soinside.com 2019 - 2024. All rights reserved.