2017-10-15 94 views
-1

我嘗試使用我在線查找的代碼。使用高級自定義字段的自定義圖庫簡碼

詳細:http://www.rinconstrategies.io/custom-gallery-shortcode-for-wordpress.html

我使用並進行調試,我看到問題的解析。

<?php 
function create_gallery_view($atts) { 
$images = get_field('gallery_view'); 

$innerHTML = ''; 
foreach($images as $image) { 
    $thumb = $image['sizes']['thumbnail']; 
    $alt = $image['alt']; 
    $caption = $image['caption']; 
    $innerHTML .= "<li> 
      <img src=$thumb alt=$alt /> 
      <p>$caption</p> 
     </li>"; 
} 

$html = <<<HTML 
<ul class="gallery-view-flex"> 
    {$innerHTML} 
</ul> 
HTML; 

echo $html; 
} 

add_shortcode('gallery_view', 'create_gallery_view'); 
?> 

在我的調試行中有一些問題。

$html = <<<HTML 
<ul class="gallery-view-flex"> 
{$innerHTML} 
</ul> 
HTML; 

    echo $html; 

我在線閱讀heredoc有這種格式。 但我motivi明白爲什麼調試說解析問題。

有人能幫我理解嗎? 謝謝 Paolo

+0

你永遠不會得到這個答案。誰應該知道你的問題?請嘗試自己瞭解問題的性質,並提出更具體的問題。 –

回答

0

heredoc結束標識符不能縮進。

錯誤

$html = <<<HTML 
HTML; // space indent 

正確

$html = <<<HTML 
HTML; // no indent 
+0

哦!非常感謝。這是) –

相關問題