2013-05-05 72 views
0

我有一個自定義帖子類型的特色圖片,我試圖在div中進行佈局。出於某種原因,圖片在頁面上但在div之外。這是我第一次使用精選圖片和自定義帖子類型。我錯過了什麼導致圖像出現在網頁之前,甚至開始div?WordPress精選圖片不在Div

if ($loop->have_posts()) { 
    $output = '<div class="stories">'; 

    while($loop->have_posts()){ 
     $loop->the_post(); 
     $meta = get_post_meta(get_the_id()); 

     $output .= ' 
      <div class="story" style="float: left; display: block; border: 1px solid #CCC;"> 
       <a href="' . get_permalink() . '"> 
        ' . get_the_title() . '</a> 
       ' . the_post_thumbnail("medium") . ' 
       ' . get_the_excerpt() . ' 

      </div> 
     '; 
    } 
    $output .= "</div>"; 
} else { 
    $output = 'No Stories Added Yet.'; 
} 

return $output; 

當我查看HTML輸出這就是呈現:

<div class="row-fluid "> 
    <img class="attachment-medium wp-post-image" width="300" height="195" alt="13755721_m" src="http://code2media.net/wp-content/uploads/2013/04/13755721_m-300x195.jpg"> 
    <img class="attachment-medium wp-post-image" width="300" height="240" alt="African-Boy" src="http://code2media.net/wp-content/uploads/2013/05/Snotty-African-Boy-300x240.jpg"> 
<div class="stories"> 
    <div class="story" style="flost: left; display: block; border: 1px solid #CCC;"> 
     <a href="http://code2media.net/stories/story-2/"> Story 2</a> 
     Test Content 
    </div> 
    <div class="story" style="flost: left; display: block; border: 1px solid #CCC;"> 
     Test Content 
    </div> 

回答

1

the_post_thumbnail("medium")立即呼應圖像縮略圖時,作爲仍在建設它的叫法,你的其他HTML外面,將一個空的返回值附加到您的字符串。如果您想該方法返回的結果將追加到您的字符串(這樣做),那麼你就需要使用get_the_post_thumbnail($post->ID, "medium")

一般來說,與the_開始WordPress的方法將呼應的結果和方法與get_啓動會返回值。

+0

謝謝。當我改變它時,沒有東西會被返回。這就像圖像的呼籲甚至不存在。 – 2013-05-05 20:49:41

+0

啊,我不得不添加$ post_id。謝謝! – 2013-05-05 20:53:16

+0

對不起,解決了它的答案。 – doublesharp 2013-05-05 20:59:05

0

the_post_thumbnail(「medium」)將以img標籤返回。你可以得到精選的圖像src並按照需要使用。

看一看this

+0

這是不正確的,'the_post_thumbnail()'會迴應結果'get_the_post_thumbnail()'將返回結果。 – doublesharp 2013-05-05 21:00:06

相關問題