【问题标题】:How to display product gallery image in the background of single product page of WoocommerceWoocommerce单品页面背景如何显示产品图库图片
【发布时间】:2018-12-09 15:23:43
【问题描述】:

我想在单个产品页面 (Woocommerce) 的背景上放置第一个产品图库图片。

我知道如何用 CSS 来设置 background-img URL,但我不是 php 开发人员,所以我很难修复它。

【问题讨论】:

  • 在函数 php 中我这样做了,但它不起作用。功能 child_filter_header_image( $default_thumbnail ) { if ( function_exists('is_product') && is_product() ) { $thumb = get_the_post_thumbnail_url(); if ( ! empty( $thumb ) ) { return $thumb; } } 返回 $default_thumbnail; } add_filter('background_image_filter', 'child_filter_header_image');

标签: php wordpress woocommerce


【解决方案1】:

未经测试!不过,你可以试试这个:

<body style="background-image: url('<?php echo get_the_post_thumbnail_url( get_the_ID(), 'large' ); ?>');">

如果您支持缩略图主题,large 应该可用。如果没有,请先将add_theme_support( 'post-thumbnails' ); 添加到您的functions.php 文件中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-14
    • 2018-08-06
    • 2023-02-08
    相关资源
    最近更新 更多