Woocommerce产品缩略图大小

时间:2014-10-09 22:46:17

标签: php wordpress size woocommerce product

我想在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的新手,我希望通过这些不同的缩略图尺寸实现砌体布局。任何帮助将不胜感激。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

请尝试以下代码:

<?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 );
?>