2014-06-19 57 views
0
<?php $args = array(
     'posts_per_page' => '12', 
     'product_cat' => 'summer', 
     'post_type' => 'product', 
     'orderby' => 'title', 
    ); 
    echo '<div class="col-xs-12 col-sm-4 col-md-4">'; 
    $query = new WP_Query($args); 
    if($query->have_posts()) : while($query->have_posts()) : $query->the_post(); 
    $src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(5600,1000), false, ''); 
    echo '<div class="wrap valshow" style="background: url(.echo $src[0];.) !important;" role="banner">'; 
    echo '<figcaption><h3><a rel="' .get_permalink(). '" href="' .get_permalink(). ' ">'; 
     the_title(); 
    echo '</a></h3></figcaption>'; 
    echo '</div>'; 
    echo '</div>'; 
    endwhile; 
    endif; 
    wp_reset_postdata(); 
?> 

我想爲woocommerce組裝一個查詢,它顯示了它的標題。我需要添加一個也鏈接到產品的按鈕。產品特色圖像作爲查詢中的背景

我想弄清楚的問題是如何將產品功能圖像集作爲背景放在上面的代碼中。我發現了一些在正常循環中工作的代碼。我曾嘗試使用

the_post_thumbnail('full'); 

其中我有echo $ src [0];但我所得到的只是一幅高於div的圖像,而不是背景。我覺得我很接近......任何幫助都會很棒,謝謝。

回答

0

你下echo

使用本使用echo

echo '<div class="wrap valshow" style="background: url(' . $src[0]; . ') !important;" role="banner">';

此外,如果您使用的是the_post_thumbnail('full');,輸出整個圖像標籤。