Reputation: 21
I'm trying to get the featured image of a post in wordpress and output it as the background image of a div and align it to the bottom right of the div.
So far I have the code shown below but the background-image: url(' . wp_get_attachment_url() . ');
is returning as background-image: url();
when the code is executed.
Thanks in advance to anyone that can help!
<?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();
?>
Upvotes: 0
Views: 730
Reputation: 9041
Try this:
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
then us $image[0]
When setting the background-image
Upvotes: 2