2

我想逐步将 div id 添加到输出的图像中,但无法弄清楚如何让它工作。例如,第一个图像输出将具有“.featured_1”,下一个将具有“.featured_2”等。

我正在使用的代码

if( function_exists('dfi_get_featured_images') ){
   $featuredImages = dfi_get_featured_images();

   //Now loop through the image to display your image

   if( !is_null($featuredImages) ){

        $links = array();

        foreach($featuredImages as $images){
            $thumb = $images['thumb'];
            $fullImage = $images['full'];

            $links[] = "<li class='zoom'><img class='zoomImg' src='{$thumb}' alt='' height='{$height}' width='{$width}' /></li>";
        }

        foreach($links as $link){
          echo $link;
        }
        echo "<div style='clear:both'></div>";
        echo "</ul>";
     }

}

我失败的尝试

    $i=1
    foreach($featuredImages as $images){
        $thumb = $images['thumb'];
        $fullImage = $images['full'];

        $links[] = "<li class='zoom featured_".$i."'><img class='zoomImg' src='{$thumb}' alt='' height='{$height}' width='{$width}' /></li>";
        $i++;
    }
4

1 回答 1

1

“我使用的代码给出了意外的 T_FOREACH 错误”

$i=1
foreach($featuredImages as $images){

您有语法错误(缺少分号)

$i=1;
foreach($featuredImages as $images){

顺便说一句,有很多代码可以满足您的真正需要

    foreach($featuredImages as $i=>$images){
        echo "<li class='zoom'><img class='zoomImg' src='".$images['thumb']."' alt='' height='{$height}' width='{$width}' /></li>";
    }
于 2013-10-30T23:54:45.727 回答