【发布时间】:2015-07-04 23:41:35
【问题描述】:
我使用我的 MySQL 数据库完成了这项工作,但大约一年前,我将我的网站改造成更方便的摄影缩略图编码布局。其他人编写了代码,它使用 opendir 功能根据特定文件夹中的图像文件自动创建缩略图。
问题是,如果我有一个包含 100 多张图片的画廊,它会将所有图片加载到页面上,并且用户在加载完之前无法选择要查看的任何内容。
我想创建分页来加载,比如说,一次加载 15 个,然后允许用户转到其他页面(如果有的话)。因为我是 PHP 新手,所以这段代码是在我头上写的。
这是我认为需要更新的相关代码:
$dir = $dir.$gallery."/";
//Put files into an array
// create a handler to the directory
$dirhandler = opendir($dir);
// read all the files from directory
$nofiles=0;
while ($file = readdir($dirhandler)) {
// if $file isn't this directory or its parent
//add to the $files array
if ($file != '.' && $file != '..')
{
$nofiles++;
$files[$nofiles]=$file;
}
}
//close the handler
closedir($dirhandler);
// sort folder names alphabetically, ignore case
natcasesort($files);
?>
<div style="clear:both"></div>
<?
//Show images
foreach ($files as $file){
if ($file!="."&&$file!="..")
{
$extention = explode('.', $file);
if ($extention[1] != "")
{
echo "<div class='imgwrapper'>";
echo"<a class='fancybox' rel='group' href='$dir$file' return='false' title='$filename'>";
echo "<img src='timthumb.php?src=$dir$file&h=$height&w=$width' alt='$extention[0]' width='$width' height='$height'>";
echo"</a><br>";
echo "</div>";
}
}
}
?>
这甚至可能不是一切。老实说,我愿意花钱请人为我做这件事。我不知道这有多难或容易。如有必要,我可以发送整个页面或复制整个代码。
我昨天花了 7 个小时试图将我的网站转换为 WordPress 布局,其中有一个 Web 画廊插件已经可以做到这一点,但是移动布局是一团糟,它比这段代码已经很容易做到的要复杂一些。
我认为我当前的网站看起来和工作都很棒,但是这个分页是唯一缺少的东西。
【问题讨论】: