我已根据我的需要调整了一个简单的分页库,但它没有按预期工作:通常它会很好地放置第一个“页面”og图片然后在某些情况下它只是跳过一些图片然后转到其他图片,在其他情况下,它只是不加载任何其他页面(我正在使用infinitescroll)
这是php函数:
function makeGallery($path, $directory, $seo){
$dir = $path . "/" . $directory;
$handle = opendir($dir);
while ($file = readdir($handle)){
if($file == '.' OR $file == '..' or $file == 'thumbs' or $file == '.DS_Store')
continue;
else
$result_array[]=$file;
}
$filecount = count(glob("" . $dir . "*.jpg"));
closedir($handle);
array_multisort($result_array, SORT_ASC);
$rows = 3;
$cols = 8;
if(isset($_GET['page'])){
$page = $_GET['page'];
}else{
$page = 0;
}
$num_pics = count($result_array);
$cells = $rows * $cols;
$pages = ceil($num_pics / $cells);
$num_pages = $pages - 1;
$output = array();
$slices = array();
$push = 0;
$showpage = $page + 1;
for($k=0;$k<$pages;$k++){
array_push($slices, $push);
$push = $push + $cells;
}
for($k=0;$k<$pages;$k++){
if($page == key($slices)){
$output = array_slice($result_array, current($slices), $cells);
}
next($slices);
}
reset($output);
print '<div class="container-fluid">
<div class="row">';
print "<ul id='photoswipe' class='thumbnails'>";
for($i=0;$i<$rows;$i++){
for($j=0;$j<$cols;$j++){
if(current($output) != false){
$value = current($output);
$parts = Explode('.', $value);
$title = $parts[count($parts) - 2];
$parts = Explode('-', $title);
$title = $parts[1];
if ($title == "") $title = $value;
print "<li class='box'><a title='$title' rel='group' class='thumbnails' href='$dir/$value'><img width='$width' height='inherrit' src='$dir/thumbs/$seo-$value' /></a></li>";
next($output);
}else{
print "</ul>";
}
}
}
$ref = $_SERVER['PHP_SELF'];
if($num_pages == '0'){
print " ";
print " ";
}elseif(($page == '0')||($page == '')){
$next = $page + 1;
print " ";
print "<a id='next' href='$ref?page=$next'> </a>";
}elseif($page == $num_pages){
$prev = $page - 1;
print "<a id='prev' href='$ref?page=$prev'> </a>";
print " ";
}else{
$next = $page + 1;
$prev = $page - 1;
print "<a id='prev' href='$ref?page=$prev'> </a>";
print "<a id='next' href='$ref?page=$next'> </a>";
}
echo "<nav id='page-nav'>
<a href='$ref?page=$next'></a>
</nav></div></div>";
}
我确定应该有一些我没有发现的愚蠢的错误,我希望一些经验丰富的php程序员可以很容易地找到它。
您可以在http://eikonabox.com/page/portrait.php上看到图库(及其问题) (在肖像库中,你可以看到它直接从24号跳到49号)
谢谢大家
答案 0 :(得分:0)
如果有人遇到这种问题,我已经解决了这个问题:
function makeGallery($path, $directory, $seo){
$dir = $path . "/" . $directory;
$filearray = array();
if ($fil = opendir($dir)) {
while (($file = readdir($fil)) !== false) {
if ($file != "." && $file != ".." && $file != "thumbs" && $file != ".DS_Store") {
$filearray[] = $file;
$page = empty($_GET['page']) ? 1 : $_GET['page'];
$num_per_page = 25;
$total_pages = ceil(count($filearray)/$num_per_page);
}
}
array_multisort($filearray, SORT_ASC);
print '<div class="container-fluid">
<div class="row">';
print "<ul id='photoswipe' class='thumbnails'>";
for($i = ($page - 1) * $num_per_page; $i < $page * $num_per_page; $i++){
$value = basename($filearray[$i]);
$parts = Explode('.', $value);
$title = $parts[count($parts) - 2];
$parts = Explode('-', $title);
$title = $parts[1];
if ($title == "") $title = $value;
if($value != "")
print "<li class='box'><a title='$title' rel='group' class='thumbnails' href='$dir/$value'><img width='$width' height='inherrit' src='$dir/thumbs/$seo-$value' /></a></li>";
}
closedir($fil);
}
print "</ul>";
$ref = $_SERVER['PHP_SELF'];
if($num_pages == '0'){
print " ";
print " ";
}elseif(($page == '0')||($page == '')){
$next = $page + 1;
print " ";
print "<a id='next' href='$ref?page=$next'> </a>";
}elseif($page == $num_pages){
$prev = $page - 1;
print "<a id='prev' href='$ref?page=$prev'> </a>";
print " ";
}else{
$next = $page + 1;
$prev = $page - 1;
print "<a id='prev' href='$ref?page=$prev'> </a>";
print "<a id='next' href='$ref?page=$next'> </a>";
}
echo "<nav id='page-nav'>
<a href='$ref?page=$next'></a>
</nav></div></div>";
}