What´s the error in this syntax?

I’m trying to do something with my Bootstrap .post-title class.

I want to put an element.style background on my post titles, which calls as a background, to the post featured image, for each post. I’ve already achieve this, but something went wrong and now isnt working. the only thing i know is must look something like this.

Read More
<div class="post-featured" style="background-image:url('upload/<?php the_post_thumbnail( 'wpbs-featured' ); ?>')">

but something in the syntax there is wrong, because it render this characters on HTML. whats going on?

')">

live example: WP Featured post image, as a div background

Related posts

Leave a Reply

2 comments

  1. the_post_thumbnail returns an IMG html tag. So the generated code is

    <div class="post-featured" style="background-image:url('upload/<img src="path/to/file.png">')">
    

    Definitely not something that could work… You want the url only, so you should do this:

    $thumb_id = get_post_thumbnail_id();
    $thumb_url = wp_get_attachment_image_src($thumb_id,'wpbs-featured', true);
    
    <div class="post-featured" style="background-image:url('<?= $thumb_url[0] ?>')">
    
  2. this is the actual html snippet working.

    <?php
    $img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full");
    $img = $img[0];
    ?>
    <div class="postfeatured" style="<?php if($img){echo 'background:url('.$img.');';} ?>">
    <div class="page-header"><h1 class="single-title" itemprop="headline"><?php the_title(); ?></h1>
    
    
      <h4> 
      <?php $mykey_values = get_post_custom_values('_aioseop_description');
      foreach ( $mykey_values as $key => $value ) {
      echo substr("$value",0 ,300); //This will display the first 150 symbols
      }?>
      </h4>
    
    
      <hr>
      <!-- Go to www.addthis.com/dashboard to customize your tools -->
      <div class="addthis_native_toolbox"></div>
      <hr>
    
      </div>
    
    </div>
    

    live example: Design Thinking. Blog de Diseño Gráfico. Picoboero