【发布时间】:2015-05-19 11:18:13
【问题描述】:
我正在 jssor 中制作一个画廊,幻灯片是通过读取一个目录并使用 PHP 脚本为每个图像编写 div 来制作的。在图像下方显示一个标题,其中包含艺术家的姓名(始终相同),后跟不带扩展名的文件名。
这是我目前所拥有的:
<?
$dir = 'Photo/Paintings';
$files = scandir($dir);
sort($files);
foreach ($files as $file) {
if ($file != '.' && $file != '..') {
echo '<div>
<img u="image" style="max-height:460px;" src="Photo/Paintings/'.$file.'" />
<img u="thumb" src="Photo/Paintings/'.$file.'" />';
$withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file);
echo '<div u="caption" style="position: absolute; top: 470px; left: 0px; height: 10px; text-align: center;">
ARTISTX - '.$withoutExt.'
</div>
</div>';
}
}
?>
这些图像应该按特定顺序排列,所以我的想法是在每个文件名的开头添加一个数字,例如#5-Picture of tree.jpg。我的问题是,如何将这个 #5 部分也从标题中显示出来?
或者,有没有更好的方法来确定这些文件的顺序?我现在意识到我的想法甚至不能很好地工作,因为 #1 会按字母顺序跟随 #11 和 #12 而不是 #2。我也许可以通过使用字母 1A、1B、1C、2A 等的组合来解决这个问题。
【问题讨论】: