php - 如何禁用 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”的内容,但这是一种有点原始的方法,我想知道这是否可以用另一种不那么原始的方法
解决方案
正如@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
瞧,现在由您来选择要保留的方法。
推荐阅读
- c# - 将单选按钮选择与数据网格中的行选择同步
- visual-studio-code - VSCode Go To Definition 不适用于`import './index.css'`
- bash - 为什么 Deployer runLocally 不能运行这个变量字符串替换命令?
- flutter - 当用户在 Flutter 中处于非活动状态时,如何将当前页面更改为另一个页面?
- html - Scrape table with no ids or classes using only standard libraries?
- r - Extracting nth character till the end of string in R
- python - Python数据框附加行具有默认值
- php - 在 VSCode 中使用 Ctrl + Click 进行 PHP 导航
- scylla - Scylladb:scylla_io_setup 脚本 iops 计算与 fio 等其他 iops 计算工具不匹配
- java - Java Spring Spring 微服务在 kubernetes 上的堆大小不足