Hi Forum,
Currently I have a thumbnail gallery that displays all of the thumbnails in a directory. However this directory has about 100 images in it (too many to display on one page). There are already some support questions regarding galleries in the forums, but all of these that I've found deal with pictures/attributes in a MySQL database and this gallery does not use a database at all.
What I would like to do is limit it to displaying only 16 thumbnails (in 3 rows each with 4 columns), and have a 'Back' and 'Next' link so that users can navigate through the thumbnail gallery in 16-thumb pages.
I have no idea how to implement this! 🙁
The page of code that generates the gallery is as follows:
<!-- begin code block
<?
$GalleryFileName = "gallery.php";
$BaseDir = "/dev/gallery";
function list_dir($dirname) {
if($dirname[strlen($dirname)-1]!='/')
$dirname.='/';
static $directory_array=array();
$handle=opendir($dirname);
while ($file = readdir($handle)) {
if($file=='.'||$file=='..') continue;
if(is_dir($dirname.$file)) {$directory_array[]=$dirname.$file;}
}
closedir($handle);
sort($directory_array);
return $directory_array;
}
function list_files($dirname) {
if($dirname[strlen($dirname)-1]!='/')
$dirname.='/';
static $files_array=array();
while (count($files_array) > 0) {Array_shift($files_array);}
$handle=opendir($dirname);
while ($file = readdir($handle)) {
if($file=='.'||$file=='..') continue;
if(!is_dir($dirname.$file)) {$files_array[]=$dirname.$file;}
}
closedir($handle);
sort($files_array);
return $files_array;
}
// # of Picture Columns to display when making gallery
$Columns = 5;
?>
<DIV ALIGN="center" Class="PhotoTitle"><?echo //$Album;?></DIV>
<?
$base_directory = "$BaseDir/thumbnails/$Album/";
$files_array = list_files($base_directory);
?>
<?}?>
<DIV ALIGN="center">
<table WIDTH="80%" BORDER="0" ALIGN="center" CELLPADDING="5" CELLPADDING="5">
<TR VALIGN="top">
<? $x = 0;
while ($x+1 <= sizeof($files_array)) {
$fileName = str_replace ($base_directory, "", current($files_array));
?>
<TD WIDTH="33%" ALIGN="center" VALIGN="top">
<a HREF="<? echo $GalleryFileName;?>?Album=<? echo $Album;?>&Pic=<? echo $fileName;?>">
<img SRC="thumbnails/<? echo $Album;?>/<? echo $fileName;?>" NAME="Img<? echo $x;?>">
<BR>
<? if ($x % $Columns == $Columns - 1) {echo "</TR>\n<TR>\n";}
next($files_array);
$x = $x + 1;
}
?>
</TR>
</table>
</DIV>
end code block -->
I have an understanding that I would need to include some sort of do-while loop in the statement for if ($x % $Columns == $Columns -1) etc...
According to a tutorial I read, this should be something like:
<!-- begin yet another code block
if page > 0 then
for i = 1 to (page * 12) + 1
//move to next record
next
else
page = 0
end if
i = 1
do until i = 12 or end of records
//display picture
if i mod 3 then (ie 3 records per row)
write end of (table?) row code
end if
move to next record
i = 1
loop
//write end of (table?) row code
if page > 0 Then
link to back page pagename.php?page= page - 1
end if
if (page * 12) + 12 < total number records
link to next page pagename.php?page= page + 1
end if
end yet another code block -->
But I need someone with more technical gnouse than me to either show me how or at least point me in the right direction...
Thanks muchly if you made it this far, too! 🙂