【问题标题】:Woocommerce Product Thumbnail sizingWoocommerce 产品缩略图大小
【发布时间】:2014-12-05 00:26:51
【问题描述】:

我正在尝试在 woocommerce 的 SHOP 页面中获取所有小型、中型和完整缩略图尺寸。我在 woocommerce.php 中使用以下代码(page.php 的副本)来显示所有产品

<?php woocommerce_content(); ?>

接下来我在functions.php中放了以下代码,但都是徒劳的

<?php
/**
 * Hook in on activation
 */

/**
 * Define image sizes
 */
function yourtheme_woocommerce_image_dimensions() {
    global $pagenow;

    if ( ! isset( $_GET['activated'] ) || $pagenow != 'themes.php' ) {
        return;
    }

    $thumbnail = array(
        'thumbnail' , 'medium' , 'large' , 'full'
    );
    $index = array_rand($sizes);
    // Image sizes
        // Single product image
    update_option( 'shop_thumbnail_image_size', $sizes[$index] );   // Image gallery thumbs
}

add_action( 'after_switch_theme', 'yourtheme_woocommerce_image_dimensions', 1 );

?>

我是 woocommerce 新手,我希望使用这些不同的缩略图大小实现砌体布局。任何帮助将不胜感激。 提前谢谢你。

【问题讨论】:

    标签: php wordpress size woocommerce product


    【解决方案1】:

    试试下面的代码:

    <?php
    /**
     * Hook in on activation
     */
    
    /**
     * Define image sizes
     */
    function yourtheme_woocommerce_image_dimensions() {
        global $pagenow;
    
        if ( ! isset( $_GET['activated'] ) || $pagenow != 'themes.php' ) {
            return;
        }
    
        $thumbnail = array(
            'thumbnail' , 'medium' , 'large' , 'full'
        );
        $index = array_rand($thumbnail);
        // Image sizes
            // Single product image
        update_option( 'shop_thumbnail_image_size', $thumbnail[$index] );   // Image gallery thumbs
    }
    add_action( 'after_switch_theme', 'yourtheme_woocommerce_image_dimensions', 1 );
    ?>
    

    【讨论】:

      猜你喜欢
      • 2023-03-22
      • 2019-02-09
      • 2014-02-24
      • 2021-02-08
      • 2021-05-24
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 2018-09-30
      相关资源
      最近更新 更多