0

我已经在网上搜索了几天,但似乎仍然找不到我想要的东西。而且我是 php 的菜鸟,我不知道如何自己想出它。我知道你们中的一个人可以帮我解决这个问题。

我想自动填充一个fancybox 画廊。我已经创建了一个可以从文件夹自动填充画廊的代码,但我无法让它在该画廊中填充两个标签:“a href”和“img src”。

<div id="content">
<a class="grouped_elements" rel="group1" href="thumb/#"><img    src="images/#" alt=""/></a>
</div>

<?php

$dirname = "./images";
$images = scandir($dirname);
$ignore = Array(".", "..");
foreach($images as $curimg){
if(!in_array($curimg, $ignore)) {
echo "<img src='./images/$curimg' /><br>\n";
};
}     
?> 

如您所见,它只填充一个文件夹中的标签。但我希望它为两个标签填充两个文件夹;每个标签都有一个不同的文件夹,“a href”和“img src”。

您的帮助将不胜感激。:)

4

1 回答 1

0

终于在另一位成员的帮助下弄清楚了。

<?php
$directory = 'thumb';   //where the gallery thumbnail images are located    
$files = glob($directory."/*.{jpg,jpeg,gif,png}", GLOB_BRACE);
natsort($files); //sort by filename
?>

<?php
for($x = 0; $x < count($files); $x++):
$thumb = $files[$x];
$file = basename($thumb);
$nomargin = $x%4 == 0?" nomargin":"";
$title = htmlspecialchars($file);
?>
<div class="thumbs fancybox<?= $nomargin ?>"
 style="background:url('<?= $thumb ?>') no-repeat 50% 50%;">
 <a rel="group" href="images/<?= $file ?>" title="<?= $title ?>"><?= $title ?></a> 
</div>
<?php
endfor;
?>
于 2013-07-07T05:13:09.030 回答