Put all the images an array and use the functions below to pagination them -
(These two functions are from a class. Modify as needed)
Code: Select all
<?php
public function paginationWithoutDb($itemsPerPage, $value, $page) {
//
if (isset($_GET['p']) && is_numeric($_GET['p'])) {
$pages = $_GET['p'];
}
else {
if (is_array($value)) {
$amount = count($value);
}
else {
echo 'The second argument for the function must be
an array';
}
if ($amount > $itemsPerPage) {
$pages = ceil($amount/$itemsPerPage);
}
else {
$pages = 1;
}
}
//
if (isset($_GET['s']) && is_numeric($_GET['p'])) {
$start = $_GET['s'];
}
else {
$start = 0;
}
//
$i = $start;
$x = 0;
echo '<ul>';
while ($x != $itemsPerPage) {
$className = ($className == "odd" ? "even" : "odd");
if ($value[$i] != '') {
echo "<li class=\"$className\">".$value[$i]."</li>";
}
$x = $x + 1;
$i = $i + 1;
}
echo '</ul>';
//
$this->createPages($page, $start, $itemsPerPage, $pages);
}
//
public function createPages($page, $start, $itemsPerPage, $pages) {
echo '<div id="pages">';
if ($pages > 1) {
$current_page = ($start/$itemsPerPage) + 1;
if ($current_page != 1) {
echo "<a href=\"$page?s=".($start-$itemsPerPage)."&p=".$pages."\">
Previous</a> ";
}
for ($i = 1; $i <= $pages; $i++) {
if ($i != $current_page) {
echo "<a href=\"$page?s=".(($itemsPerPage * ($i-1)))."&p=".$pages."\">".$i."</a> ";
}
else {
echo '<span>'.$i.'</span> ';
}
}
if ($current_page != $pages) {
echo " <a href=\"$page?s=".($start+$itemsPerPage)."&p=".$pages."\">
Next</a>";
}
}
echo '</div>';
}
?>
On the page you implement the pagination the code looks as follows :
Code: Select all
<?php
//write all your image names into an array.
$value = array('Bill', 'Dick', 'Spot', 'Klaus', 'Nadia', 'Petra', 'Dieter', 'Juniper', 'Jalepeno');
//5 is the amount of items per page.
//$value is the name of the array
//$_SERVER['PHP_SELF'] is the pagename (change as needed)
$untitled->paginationWithoutDb(5, $value, $_SERVER['PHP_SELF']);
?>
Hope this helps.