2017-10-15 92 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

哦!非常感谢。这是) –

相关问题