2017-02-05 3 views
-2

私はwoocommerceのlighboxでフルサイズの画像を大きな画像に置き換えたいと考えています。Wocommerceフルサイズimg with large - product-image.php

<?php 
    if (has_post_thumbnail()) { 
     $image    = get_the_post_thumbnail($post->ID, apply_filters('single_product_large_thumbnail_size', 'shop_single')); 
     $image_title  = esc_attr(get_the_title(get_post_thumbnail_id())); 
     $image_link   = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID)); 
     $attachment_count = count($product->get_gallery_attachment_ids()); 

     if ($attachment_count > 0) { 
      $gallery = '[product-gallery]'; 
     } else { 
      $gallery = ''; 
     } 
     echo apply_filters('woocommerce_single_product_image_html', sprintf('<a href="%s" itemprop="image" class="bigbox woocommerce-main-image zoom" title="%s" rel="prettyPhoto' . $gallery . '">%s</a>', $image_link, $image_title, $image), $post->ID); 

    } else { 

     echo apply_filters('woocommerce_single_product_image_html', sprintf('<img src="%s" alt="Placeholder" class="bigbox" />', woocommerce_placeholder_img_src()), $post->ID); 

    } 
?> 

<?php do_action('woocommerce_product_thumbnails'); ?> 

私は運と

$image_link = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large'); 

に$画像リンクを変更しようとした -

は、ここに私のコードです。

答えて

1

$ image_linkは配列として返されます。画像リンクをエコーする、

<?php echo $image_link[0]; ?>

は、だからあなたの完全なコードは this

+0

ほとんどそこに、私は小さなサムネイルを得ています。どのように大きな画像を取得するための任意のアイデア? –

+0

元のコードにフィルタがある場合は、コードを再度繰り返さないでください。 – Christina

+0

私はこのSahriar Saikatのヒントとこのコードの問題を解決しました: $ image_link = wp_get_attachment_image_src(get_post_thumbnail_id($ post-> ID)、 'shop_single'); –

1

WooCommerceはフィルタ「woocommerce_single_product_image_html」を持っているように、あなたは、このためのあなたのテーマ内のコードを繰り返さないでなければなりません、してみてください。

functions.phpまたは関数プラグインに次の行を追加します。

注:これは2.6xで動作し、単一の画像表示を大きく変更したため2.7で動作しません。

function yourprefix_woocommerce_single_product_image_html($html, $post_id) { 

    if (! class_exists('WooCommerce')) return; 
    //bail if WooCommerce is not installed and active since we are using the WC_VERSION constant 

    if (version_compare(WC_VERSION, '2.7', '<')) { 

     $image_title = esc_attr(get_the_title(get_post_thumbnail_id())); 
     $image_link = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large'); //this is where and use the [0] on this variable in the sprintf  
     $image = get_the_post_thumbnail($post_id, 'shop_single', array('title' => $image_title)); 
     $html = sprintf('<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s">%s</a>', $image_link[0], $image_title, $image ); 

    } //end version compare still return the html so we don't get an error 

    return $html; 

} 
add_filter('woocommerce_single_product_image_html', 'yourprefix_woocommerce_single_product_image_html', 10, 2); 

注:wp_get_attachment_image_src()は、デフォルトのコードで使用されるものではありません、それは画像のアップロード、ないサイズの画像を取得しwp_get_attachment_image_url()です。生成されたイメージを使用したい場合は、$ variable = wp_get_attachment_image_src(...)を使用します。 url、$ variable [1] width、$ variable [2] heightの$ variable [0]を指定します。これにはたくさんのツーツがあるので、私は繰り返さないでしょう

+0

私はサハリアのあなたの最後のコメントに同意します...だから私はこの答えを投票しました。 – LoicTheAztec

+1

ありがとうございます。人々がフィルタを無視し、メンテナンスの難しいコードをたくさん作成するのは奇妙です。 – Christina

+0

私はあなたに同意することができます。フィルタを繰り返す必要はありませんが、コードで空白のページが表示されました。 –