• Resolved moffepoffe

    (@moffepoffe)


    Hey,

    I’ve been trying to deal with a huge problem which i cannot solve, i’ve been googleing and trying different techniques to get this to work.

    single-gigs.php

    get_header(); ?>
    
    <div id="container">
    <div id="gigpres">
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    
    <div style="background: url(<?php the_post_thumbnail( 'thumbnail' ); ?>
    ) !important;">adasdasdasd </div>

    this returns a <img scr source when opening in chrome, how go i get the the_post_thumbnail to just give me the source of the file without <img scr?

    <div id="container">
    		<div id="gigpres"> 
    
    <div style="background: url(<img width="150" height="150" src="https://xxxx/the-2-live-crew-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="the-2-live-crew" title="the-2-live-crew" />) !important;">adasdasdasd </div>
    		</div>
    		</div>

    Thanks in advance,
    Moffe

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter moffepoffe

    (@moffepoffe)

    Nevermind, i was to lazy to try one thing that worked.

    If any1 runs into this problem use the following code

    <?php global $post; ?>
    <?php
    $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, '' );
    ?>
    <div style="background: url(<?php echo $src[0]; ?> ) !important;">text </div>

    Thanks! Exactly what I needed to find! I tried placing this outside of the loop and it used the same pic for every background. Eventually I figured it out.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Insert featured image in div style background’ is closed to new replies.