简体   繁体   English

在一行上显示 woocommerce 产品图库缩略图为 slider

[英]Display woocommerce product gallery thumbnails on one row as slider

On woocommerce single product page, the default for gallery thumbnails appears under active image in rows.在 woocommerce 单个产品页面上,画廊缩略图的默认值按行显示在活动图像下方。 Currently for me it's displaying 4 images per row.目前对我来说,它每行显示 4 张图像。

I believe Woocommerce uses flexslider for product page slider.我相信 Woocommerce 将 flexslider 用于产品页面 slider。

So since we are going to have lots of images for each product, I'm looking to add slider navigation to the product gallery while avoiding another plugin.因此,由于我们将为每个产品提供大量图像,因此我希望将 slider 导航添加到产品库,同时避免使用其他插件。 As a result, the product gallery will then show all images on only 1 single row.因此,产品库将仅在 1 行上显示所有图像。

Like flexslider2flexslider2

What would be the best way to achieve this?实现这一目标的最佳方法是什么? - Can it be done with pure CSS or would one need to add slider navigation using WordPress filters and CSS? - 可以使用纯 CSS 来完成,还是需要使用 WordPress 过滤器和 Z2C56C35861Z360580D485BDFED9?

在此处输入图像描述

在此处输入图像描述

CSS CSS

flex-control-thumbs {
  width: 90%;
  position: absolute;
  bottom: 0px; 
  text-align: center;
  display:flex;
  flex-wrap:nowrap;
  
  border: 1px solid red;
  overflow-x:auto;
  padding-bottom:10px;
}

.flex-control-thumbs li {
  margin: 0 6px;
  display: inline-block;
  zoom: 1;
}


.flex-control-thumbs li,
.flex-control-thumbs li:first-child {
  width: 16%;
  vertical-align: top;
  margin: 5px 1% 0 0;
  min-width: 100px;
}

.flex-control-thumbs img {
  width: 100%;
  display: block;
  opacity: 0.8;
  cursor: pointer;
}

.flex-control-thumbs img:hover {
  opacity: 0.5;
}

.flex-control-thumbs .flex-active {
  opacity: 1;
  cursor: default;
}

.product_slider .flex-active-slide a:hover {
  cursor: -webkit-zoom-in;
  cursor: -moz-zoom-in;
}

Outer HTML from WC WC 外 HTML

<ol class="flex-control-nav flex-control-thumbs">
    <li><img src="image.jpeg" class="flex-active" draggable="false" /></li>
    <li><img src="image.jpeg" draggable="false" /></li>
    <li><img src="image.jpeg" draggable="false" /></li>
    <li><img src="image.jpeg" draggable="false" /></li>
    <li><img src="image.jpeg" draggable="false" /></li>
    <li><img src="image.jpeg" draggable="false" /></li>
</ol>

// Add slider navigation using WordPress filters. // 使用 WordPress 过滤器添加 slider 导航。

add_filter( 'woocommerce_single_product_carousel_options', 'cuswoo_update_woo_flexslider_options' );
/** 
 * Filer WooCommerce Flexslider options - Add Navigation Arrows
 */
function cuswoo_update_woo_flexslider_options( $options ) {

    $options['directionNav'] = true;

    return $options;
}

UPDATE更新

Here is CSS for the Navigation controls / for the Fliter above (next & previous image).这是导航控件的 CSS / 上面的 Fliter(下一个和上一个图像)。

ul.flex-direction-nav {
    position: absolute;
    top: 30%;
    z-index: 99999;
    width: 100%;
    left: 0;
    margin: 0;
    padding: 0px;
    list-style: none;}

li.flex-nav-prev {float: left;}
li.flex-nav-next {float: right;}
a.flex-next {visibility:hidden;}
a.flex-prev {visibility:hidden;}
a.flex-next::after {visibility:visible;content: '\f105';
    font-family: FontAwesome;margin-right: 10px;font-size: 70px;    }
a.flex-prev::before {
    visibility:visible;
    content: '\f104';
    font-family: FontAwesome;    margin-left: 10px;font-size: 70px;}

to solve this you need to add a horizontal slider if thumbnails are many, and some more CSS grid code to make it responsive and spaced properly, I hope you find this useful.要解决这个问题,如果缩略图很多,您需要添加一个水平 slider,以及一些更多的 CSS 网格代码以使其响应和间隔适当,我希望你觉得这很有用。

 .woocommerce-product-gallery { display: grid; gap: 10px } @media only screen and (max-width: 35.999em) {.woocommerce-product-gallery { gap: 6px; } }.woocommerce-product-gallery.flex-control-thumbs { display: grid; grid-auto-flow: column; grid-auto-columns: 17%; gap: 1rem; overflow-x: auto;important: overscroll-behavior-inline; contain: } @media screen and (max-width. 47.999em) {.woocommerce-product-gallery:flex-control-thumbs { grid-auto-columns. 12;5%: gap; 6px. } }.woocommerce-product-gallery:flex-control-thumbs li { float; none:important; width: 100%;important. display. grid: };woocommerce-product-gallery:flex-control-thumbs li img { inline-size; 100%: aspect-ratio; 1/1: -o-object-fit; cover: object-fit; cover. border-radius. 5px. }:woocommerce-product-gallery;flex-control-thumbs li img:flex-active { border. 5px solid #f2f2f2. } @media screen and (max-width. 47.999em) {:woocommerce-product-gallery;flex-control-thumbs li img.flex-active { border. 2px solid #f2f2f2: } };woocommerce-product-gallery:flex-control-nav { -ms-scroll-snap-type; inline mandatory: scroll-snap-type; inline mandatory. scroll-padding-inline. 10px: };woocommerce-product-gallery .flex-control-nav > * { scroll-snap-align: start; }

if you wish to also add the navigation the code is easy if need help I can assist如果您还想添加导航代码很容易如果需要帮助我可以提供帮助

Cheers!干杯!

Hello the code worked for me for displaying a horizantal scroll bar under the main product photo with special CSS, but now the thumbnails are missing.您好,代码对我有用,用于在带有特殊 CSS 的主要产品照片下显示水平滚动条,但现在缺少缩略图。 What can i do?我能做些什么? I searched for this (More Thumnail Images Under the Product Photo) on internet but could not find a solution.我在互联网上搜索了这个(产品照片下的更多缩略图),但找不到解决方案。

Which codes should i use?我应该使用哪些代码? Will i have to change theme functions and how?我是否必须更改主题功能以及如何更改? Thanks a lot...非常感谢...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM