我对 PHP 中的相册有疑问。画廊有以下结构:
<div class="imageElement">
<h3>Item 1 Title</h3>
<p>Item 1 Description</p>
<a href="open/1.jpg" title="open image" class="open"></a>
<img src="big/1-gallery.jpg" class="full" />
<img src="thumb/1-mini.jpg" class="thumbnail" />
</div>
and so on
我有三个文件夹:大 - 带有普通图像,拇指 - 带有拇指,打开 - 带有大图像。
我创建了一个 foreach 循环:
<?php foreach(glob("images/folder/images/".$id."/big/*.jpg") as $filename) : ?>
<div class="imageElement">
<h3>Item 1 Title</h3>
<p>Item 1 Description</p>
<a href="path-to-large-image" title="open image" class="open"></a>
<? echo '<img src="'.$filename.'" class="full">'?>
<?php foreach(glob("images/folder/images/".$id."/thumb/*.jpg") as $filename2) : ? >
<? echo '<img src="'.$filename2.'" class="thumbnail">';break;?>
<?php endforeach ?>
</div>
<?php endforeach ?>
不幸的是,我只得到了第一个 - 每个图像都使用相同的拇指。在这种情况下我应该如何使用 foreach 循环?我应该如何使用下一个循环从打开的文件夹中获取图像?
感谢您的回答。
编辑:
我在 html 中的输出看起来:
<div class="imageElement">
<h3>title</h3>
<p>text</p>
<a href="/images/folder/4/open/1.jpg" title="open image" class="open"></a>
<a href="/images/folder/4/open/2.jpg" title="open image" class="open"></a>
<a href="/images/folder/4/open/3.jpg" title="open image" class="open"></a>
<a href="/images/folder/4/open/4.jpg" title="open image" class="open"></a>
<img src="images/folder/images/4/big/1.jpg" class="full">
<img src="/images/folder/images/4/thumb/1.jpg" class="thumbnail">
<img src="/images/folder/images/4/thumb/2.jpg" class="thumbnail">
<img src="/images/folder/images/4/thumb/3.jpg" class="thumbnail">
<img src="/images/folder/images/4/thumb/4.jpg" class="thumbnail">
</div>
<div class="imageElement">
<h3>title</h3>
<p>text</p>
<a href="/images/folder/4/open/1.jpg" title="open image" class="open"></a>
<a href="/images/folder/4/open/2.jpg" title="open image" class="open"></a>
<a href="/images/folder/4/open/3.jpg" title="open image" class="open"></a>
<a href="/images/folder/4/open/4.jpg" title="open image" class="open"></a>
<img src="images/folder/images/4/big/2.jpg" class="full">
<img src="/images/folder/images/4/thumb/1.jpg" class="thumbnail">
<img src="/images/folder/images/4/thumb/2.jpg" class="thumbnail">
<img src="/images/folder/images/4/thumb/3.jpg" class="thumbnail">
<img src="/images/folder/images/4/thumb/4.jpg" class="thumbnail">
</div>
等等。
它应该看起来:
<div class="imageElement">
<h3>title</h3>
<p>text</p>
<a href="/images/folder/4/open/1.jpg" title="open image" class="open"></a>
<img src="images/folder/images/4/big/1.jpg" class="full">
<img src="/images/folder/images/4/thumb/1.jpg" class="thumbnail">
</div>
<div class="imageElement">
<h3>title</h3>
<p>text</p>
<a href="/images/folder/4/open/2.jpg" title="open image" class="open"></a>
<img src="images/folder/images/4/big/2.jpg" class="full">
<img src="/images/folder/images/4/thumb/2.jpg" class="thumbnail">
</div>