Code: Select all
<?php
########## settings for news
$pg['limit'] = 5; // items per page
########## determine pages
$query['count_news'] = mysql_query ("SELECT count(*) FROM `news`");
$pg['total'] = mysql_fetch_row ($query['count_news']); // total number of items
$pg['total'] = $pg['total'][0];
##### retrieve news for current page
$pg['current'] = $args[1];
if (empty ($pg['current'])) $pg['current'] = 1; // no page has been requested
$pg['start'] = $pg['current'] * $pg['limit'] - ($pg['limit']);
##### create links to pages
### previous link
if ($pg['current'] != 1) { // current page is not the first
$pg['prev_pg'] = $pg['current'] - 1;
$pg['prev_link'] = "[url2={$fself}{$pg['prev_pg']}/]« previous[/url2]";
} else { $pg['prev_link'] = "« previous"; }
### next link
if (($pg['total'] - ($pg['limit'] * $pg['current'])) > 0) { // there are more items remaining
$pg['next_pg'] = $pg['current'] + 1;
$pg['next_link'] = "[url2={$fself}{$pg['next_pg']}/]next »[/url2]";
} else { $pg['next_link'] = "next »"; }
### page links (numbers)
$pg['total_pg'] = $pg['total'] / $pg['limit'];
for($i = 1; $i <= $pg['total_pg']; $i++){ // loop trough each page link
if ($i == $pg['current']) { $pg['num_links'] .= "{$i} "; }
else { $pg['num_links'] .= "[url2={$fself}{$i}/]{$i}[/url2] "; };
} // loop trough each page link
if(($pg['total'] % $pg['limit']) != 0) {
if ($i == $pg['current']) { $pg['num_links'] .= "{$i} "; }
else { $pg['num_links'] .= "[url2={$fself}{$i}/]{$i}[/url2] "; };
}
######### /determine pages ##########
?>However, i've decided to change into another system, which only shows the 3 pages before and after, instead of the old one which just links to all pages available, since the list can get very long.« previous | 1 2 3 4 5 6 7 8 9 10 11 12 | next »
It should output something like this (if current page is 5):
I can't come up with any idea on how to do this, so I decided to ask here. Have anyone done this before, or have you got any links to example code / guides regarding pagination in this way?« previous | 2 3 4 5 6 7 8 | next »
