1 ) $page = (int)$_GET['page']; $imgPerPage = 12; // you can change this $start = ($page-1)*$imgPerPage; $stop = $start + $imgPerPage; foreach (glob($directory.'/*.{jpg,jpeg,png,gif}', GLOB_BRACE) as $file){ if($file=='.' || $file == '..') continue; if($i< $start || $i>=$stop) { $i++; continue; } $file_parts = explode('.',$file); $ext = strtolower(array_pop($file_parts)); $title = basename($file); $title = htmlspecialchars($title); $nomargin=''; if(($i+1)%4==0) $nomargin='nomargin'; echo '
'; $i++; } ?>

 


1) { $pagination .= "
1) $pagination .= "« prev"; else $pagination .= "« prev"; //pages if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination .= "$counter"; else $pagination .= "$counter"; } } elseif($lastpage >= 7 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if($page < 1 + ($adjacents * 3)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) $pagination .= "$counter"; else $pagination .= "$counter"; } $pagination .= "..."; $pagination .= "$lpm1"; $pagination .= "$lastpage"; } //in middle; hide some front and some back elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination .= "1"; $pagination .= "2"; $pagination .= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination .= "$counter"; else $pagination .= "$counter"; } $pagination .= "..."; $pagination .= "$lpm1"; $pagination .= "$lastpage"; } //close to end; only hide early pages else { $pagination .= "1"; $pagination .= "2"; $pagination .= "..."; for ($counter = $lastpage - (1 + ($adjacents * 3)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination .= "$counter"; else $pagination .= "$counter"; } } } //next button if ($page < $counter - 1) $pagination .= "next »"; else $pagination .= "next »"; $pagination .= "
\n"; } return $pagination; } ?>