我想逐步将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++;
}
答案 0 :(得分: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>";
}