WordPress的 - 在PHP中使用精选图像作为div背景

问题描述:

我试图在wordpress中获取一篇文章的精选图片,并将其作为div的背景图片输出,并将其与div的右下角对齐。WordPress的 - 在PHP中使用精选图像作为div背景

到目前为止,我的代码如下所示,但执行代码时background-image: url(' . wp_get_attachment_url() . ');返回为background-image: url();

在此先感谢任何人,可以帮助!

<?php 
    query_posts(array('category_name' => 'what-we-do')); 
    if(have_posts()) : while(have_posts()) : the_post(); 
?> 
<div> 
    <?php 
     echo do_shortcode(' 
      [expand title="' . get_the_title() . '" swaptitle="Close" trigpos="below" id="' . get_the_ID() . '" trigclass="arrowright" rel="whatwedo-highlander"] 
       <h4 class="collapse-inner-title">' . get_the_title() . '</h4> 
       <div class="whatwedo-collapse-background-img" style="background-image: url(' . wp_get_attachment_url() . '); background-position: right bottom;"> 
        <div class="whatwedo-collapse-content">' . get_the_content() . '</div> 
       </div> 
      [/expand] 
     '); 
    ?> 
</div> 

<?php 
    endwhile; 
    endif; 
    wp_reset_query(); 
?> 

试试这个:

$image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail');

然后我们$image[0]当设置background-image

+0

你,先生,是一位绅士。感谢您的快速响应和明确的说明。完美工作。 – AdamPool 2014-09-25 11:16:54

+0

乐意帮忙... – Alex 2014-09-25 11:20:07