2017-05-04 7 views
0

私の背景イメージの表示に問題があります。ループ内の背景イメージを表示し、if文ワードプレス

投稿を表示して背景画像を設定しようとするループを作成しましたが、どこかに壊れていますか?以下はループ内の私のコードです。

<div class="artist-feed"> 
<?php 
    $artistloop = new WP_Query(array('post_type' => 'artist')); 
    if ($artistloop->have_posts()) : 
     while ($artistloop->have_posts()) : $artistloop->the_post(); ?> 

       <a href="<?php the_permalink(); ?>"> 
        <div class="single-artist" style="background-image: url(<?php echo the_post_thumbnail(); ?>);"> 
        <div class="artist-info"> 
         <h2><?php echo get_the_title(); ?></h2> 
        </div> 
        </div> 
       </a> 
     <?php endwhile; 
     endif; 
    wp_reset_postdata(); 
?> 
</div> 

答えて

0

あなたの問題はthe_post_thumbnail()への呼び出しです。このメソッドは実際にサムネイルを表示し、URLは表示しません。ここを参照してください:

https://developer.wordpress.org/reference/functions/the_post_thumbnail/

get_the_post_thumbnail_url()を試してみてください、あなたのサムネイルのURLを取得するには。これはあなたが必要とするものでなければなりません。ここを参照してください:

https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/

+0

おかげでクリス!だからシンプルな....私はそれを見落として信じられない。 –

+0

問題はありません:)これは私を永遠に理解するのにもかかりました。私はWordpressが最終的に 'get_the_post_thumbnail_url()'メソッドを追加してうれしいです – Chris

関連する問題