To display a thumbnail of a post as a background image, it is sufficient to use the following code:
1 2 3 4 | <?php $thumbnail_id = get_post_thumbnail_id($post->ID); $thumbnail_object = get_post($thumbnail_id); echo ($thumbnail_object->guid); ?> |
This code gets the URL of the attached image. On an example it looks like this:
1 2 3 4 | <div class="background" style="background: url(' <?php $thumbnail_id = get_post_thumbnail_id($post->ID); $thumbnail_object = get_post($thumbnail_id); echo ($thumbnail_object->guid); ?> ')"> |
The code is basically suitable for entries, pages, products and product categories.