您可以glob()
使用 PHP 生成一个目录来生成缩略图。我在我的摄影网站上使用这种方法:
<?php
$counter = 0; // Set counter to 0
foreach (glob("images/photo-strip/thumb/*.jpg") as $pathToThumb) { // Grab files from the thumbnail path and save them to variable
$th_filename = basename($pathToThumb); // Strip the thumbnail filename from the path
$filename = str_replace('th_', '', $th_filename); // Strip th_ from the filename and save it to a different variable
$pathToFull = 'images/photo-strip/' . $filename; // Rebuild the path to the full-size image
echo ("<section class=\"photo-box\"><a href=\"$pathToFull\"><img src=\"$pathToThumb\" /></a></section>"); // Echo the photobox
$counter++; // Increment counter by 1 until no file exists
}
?>
您可以扩展此代码以生成您的“标题”,甚至可以为标签title=""
内的属性设置标题样式<img>
。如何将这些标题与文件匹配取决于您。