2013-12-23 18 views
0

我正在使用高級自定義字段來顯示使用簡碼的團隊BIOS,客戶端回到我身邊,想要一個自定義圖像大小,然後通過CSS屏蔽。

它工作正常,直到我試圖添加自定義圖像。使用wp_get attachment_src,我相信我在做一個明顯的PHP埃羅,你能不能幫我排查,

代碼:

function team_profiles_func($atts) { 
     global $post; 
     extract(shortcode_atts(array(
      'id' => $post->ID 
     ), $atts)); 
     if (get_field('team_profiles')) { 
      while (has_sub_field('team_profiles')) { 
       $attachment_id = get_sub_field('employee_photo'); 
       $size = "team"; 
       $image = wp_get_attachment_image_src($attachment_id, $size); 

       $output .= '<div class="crew-wrap media">'; 
       $output .= ' <a class="crew-img" href="#">'; 
       $output .= ' <img src="'.echo $image[0].'" class="media-object" alt="">'; 
       $output .= ' </a>'; 
       $output .= ' <div class="media-body">'; 
       $output .= '  <h2 class="media-heading">'.get_sub_field('employee_name').'</h2>'; 
       $output .= '  <h4 class="media-heading">'.get_sub_field('employee_title').'</h4>'; 
       $output .= '  <p>'.get_sub_field('employee_bio').'</p></div>'; 
       $output .= '</div>'; 
      } 
     } 
     return $output; 
    } 
+1

如果你做了'var_dump()','$ image'是什麼? – putvande

+1

它正在工作,直到..所以確定,但發生什麼事情呢?輸出是什麼?你是怎麼想到,那你實際看到的,HWAT沒有error_log裏說,你是怎麼調試爲@putvande說,等等等等請教自己:) – Nanne

回答

-1

你可以從PHP腳本沒有輸出PHP,並有它執行。 PHP在網絡服務器上執行。所以客戶不知道該如何處理它。

相反試試這個:

$output .= ' <img src="' . $image[0] . '" class="media-object" alt="">'; 
+0

當然,你可以:?'回聲「'' –

+0

你可以這樣做,但它只會顯示而不是富。 –

+0

你在'output'和'execute'之間沒有看到任何區別? –

2

echo是一個語言結構確實有返回值:

$output .= ' <img src="'.echo $image[0].'" class="etc... 
          ^^^^---incorrect 

echo將直接在$image[0]作爲輸出轉儲值,您最終生成

<img src="" class=" etc... 

你應該有

$output .= ' <img src="'. $image[0] .'" class=" etc.. 

注缺乏呼應。

0

$size變量可以是字符串的關鍵字(縮略圖,中型,大型或全部)或表示以像素爲單位的寬度和高度的2項數組,例如陣列(32,32)。 "team"是什麼意思?