A więc klasa do paginacji:
<?
class pagination
{
var $page = 1; // Current Page
var $perPage = 10; // Items on each page, defaulted to 10
var $showFirstAndLast = false; // if you would like the first and last page options.
function generate($array, $perPage = 10)
{
// Assign the items per page variable
if (!empty($perPage))
$this->perPage = $perPage;
// Assign the page variable
if (!empty($_GET['page'])) {
$this->page = $_GET['page']; // using the get method
} else {
$this->page = 1; // if we don't have a page number then assume we are on the first page
}
// Take the length of the array
$this->length = count($array);
// Get the number of pages
$this->pages = ceil($this->length / $this->perPage);
// Calculate the starting point
$this->start = ceil(($this->page - 1) * $this->perPage);
// Return the part of the array we have requested
return array_slice($array, $this->start, $this->perPage);
}
function links()
{
// Initiate the links array
$plinks = array();
$links = array();
$slinks = array();
// Concatenate the get variables to add to the page numbering string
if (count($_GET)) {
$queryURL = '';
foreach ($_GET as $key => $value) {
if ($key != 'page') {
$queryURL .= '&'.$key.'='.$value;
}
}
}
// If we have more then one pages
if (($this->pages) > 1)
{
// Assign the 'previous page' link into the array if we are not on the first page
if ($this->page != 1) {
if ($this->showFirstAndLast) {
$plinks[] = ' <a href="?page=1'.$queryURL.'">«« First </a> ';
}
$plinks[] = '<span class="poprzednia"> <a href="?page='.($this->page - 1).$queryURL.'">« Poprzednia</a></span> ';
}
// Assign all the page numbers & links to the array
for ($j = 1; $j < ($this->pages + 1); $j++) {
if ($this->page == $j) {
$links[] = ' <span class="selected">'.$j.'</span> '; // If we are on the same page as the current item
} else {
$links[] = '<span class="srodkowe"> <a href="?page='.$j.'">'.$j.'</a> </span>'; // add the link to the array
}
}
// Assign the 'next page' if we are not on the last page
if ($this->page < $this->pages) {
$slinks[] = '<span class="poprzednia"> <a href="?page='.($this->page + 1).$queryURL.'"> Następna » </a> </span>';
if ($this->showFirstAndLast) {
$slinks[] = ' <a href="?page='.($this->pages).$queryURL.'"> Last »» </a> ';
}
}
//http://4programmers.net/Forum/PHP/120220-Php_StronicowaniePaginacja_wyswietlanie_ilosci_stron?p=824211#id824211/
// Push the array into a string using any some glue
return implode(' ', $plinks).implode(/*$this->implodeBy,*/ $links).implode(' ', $slinks);
}
return;
}
}
?>
problem rodzi się tu np tu:
if ($this->page < $this->pages) {
$slinks[] = '<span class="poprzednia"> <a href="?page='.($this->page + 1).$queryURL.'"> Następna » </a> </span>';
if ($this->showFirstAndLast) {
$slinks[] = ' <a href="?page='.($this->pages).$queryURL.'"> Last »» </a> ';
}
}
A dokładniej tu (chodzi o samego hrefa):
$slinks[] = ' <a href="?page='.($this->pages).$queryURL.'"> Last »» </a> ';
On dopisuje do końca linka to: ?page='.($this->pages).$queryURL.
np:
Chcę, żeby wyglądało to tak:
http://127.0.0.1/travel/kultura/galerie/handlowe/page/2 etc ...page/3, ...page/4, ...page/n
Obecnie wygląda to tak:
http://127.0.0.1/travel/kultura/galerie/handlowe?page=2
Jak zmienię na coś takiego: <a href="/page/'.($this->pages).$queryURL.'">
To wychodzi mi, że ucina ostatnie słowo z linka:/ :
http://127.0.0.1/travel/kultura/galerie/page/1
A ma być tak:
http://127.0.0.1/travel/kultura/handlowe/galerie/page/1
Czyli nie działa mi :( nie pobiera mi $_GET['page'].
Tu jeszcze .htaccess:
RewriteRule ^kultura/([a-z]+)/([a-z]+)/([a-z]+)/([0-9]+)/?$ kultura.php?a=$1&strona=$2&p=$3&page=$4 [L]
Może w przyjaznych linka coś zmienić? Np. końcówkę z:&page=$4
na : ?page=$4
Zaraz będę kombinował, ale za wszelką pomoc udzieloną z waszej strony też liczę, bo ja już się męczę trochę i nie wychodzi :/