It is quite handy if you have a lot of pages and posts
|
|
This has a little to do with standard Seditio pagination and Sedplus, but it is very common with what is used in vBulletin or Invision. Here is a complete guide how to turn standard Seditio pagination into vBulletin-style. Note that it's implemented as a corehack for two reasons: first this way it works faster, then it's designed as a replacement for standard Seditio code, rather than plugin.
1. Edit your system/functions.php, add the following function to the bottom of the file:
function sed_build_pagnav($totalitems, $perpage, $address, $pagenumber, $disable_pageof = false)
{
// CONFIG
$L['First'] = 'First'; // First
$L['Last'] = 'Last'; // Last
$L['page_of'] = 'Page %1$s of %2$s'; // Page of
$each_side = 3; // Links each side
// DO NOT EDIT BELOW
// Numbers
$totalpages = ceil($totalitems / $perpage);
$currentpage = floor($pagenumber / $perpage);
// Next/prev & first/last
if ($pagenumber > 0)
{
$prev_n = $pagenumber - $perpage;
if ($prev_n < 0) { $prev_n = 0; }
$prev = '<span class="pagenav_prev"><a href="'.$address.$prev_n.'"><</a></span>';
$first = '<span class="pagenav_first"><a href="'.$address.'0"><strong>«</strong> '.$L['First'].'</a></span>';
}
if (($pagenumber + $perpage) < $totalitems)
{
$next_n = $pagenumber + $perpage;
$next = '<span class="pagenav_next"><a href="'.$address.$next_n.'">></a></span>';
$last_n = ($totalpages-1)*$perpage;
$last = '<span class="pagenav_last"><a href="'.$address.$last_n.'">'.$L['Last'].' <strong>»</strong></a></span>';
}
// Rest
$i = 0;
$n = 0;
$pages = '';
$cur_left = $currentpage - $each_side;
$cur_right = $currentpage + $each_side + 1;
$passed = false;
while($i < $totalpages)
{
$mul = ($n % 2 == 0) ? 2 : 5;
// Current & each side
if(($i >= $cur_left && !$passed) || ($currentpage < 10 && !$passed))
{
// Left side
$start = ($cur_left <= 0) ? 0 : $cur_left;
for($j = $start; $j < $currentpage; $j++)
{
$k = $j * $perpage;
$pages .= '<span class="pagenav_pages"><a href="'.$address.$k.'">'.($j+1).'</a></span>';
}
// Current
$pages .= '<span class="pagenav_current">'.($currentpage+1).'</span>';
// Right side
$stop = ($cur_right > $totalpages) ? $totalpages : $cur_right;
for($j = $currentpage + 1; $j < $stop; $j++)
{
$k = $j * $perpage;
$pages .= '<span class="pagenav_pages"><a href="'.$address.$k.'">'.($j+1).'</a></span>';
}
// Move pointer if needed
if($cur_right + 1 > $i * $mul) $n++;
$passed = true;
}
else
{
$k = $i * $perpage;
$pages .= '<span class="pagenav_pages"><a href="'.$address.$k.'">'.($i+1).'</a></span>';
}
if($i < 10) $i = 10;
else $i = $i * $mul;
$n++;
}
// Result
if(!$disable_pageof) $pagnav = '<span class="pagenav_title">'.sprintf($L['page_of'], $currentpage+1, $totalpages).'</span>: ';
$pagnav .= $first;
$pagnav .= $prev;
$pagnav .= $pages;
$pagnav .= $next;
$pagnav .= $last;
return $pagnav;
}
You may want to change values in the CONFIG section before you use it.
2. Edit your skin's CSS and design the outlook for your pagination. Here is an example:
.pagenav_title, .pagenav_first, .pagenav_last {
margin:0px 2px 0px 2px;
padding:0px 2px 0px 2px;
}
.pagenav_pages, .pagenav_prev, .pagenav_next, .pagenav_current{
margin:0px 2px 0px 2px;
padding:0px 2px 0px 2px;
font-weight: bold;
}
.pagenav_pages a, .pagenav_first a, .pagenav_last a, .pagenav_prev a, .pagenav_next a {
text-decoration:none;
}
.pagenav_current {
text-decoration:underline;
font-weight:normal;
}
3. Edit system/core/forums/forums.posts.inc.php:
Find
"FORUMS_POSTS_PAGES" => $pages,
Replace:
'FORUMS_POSTS_PAGES' => sed_build_pagnav($totalposts, $cfg['maxtopicsperpage'], "forums.php?m=posts&q=$q&d=", $d),
And use {FORUMS_POSTS_PAGES} in your skin's forums.posts.tpl.
4. Edit system/core/forums/forums.topics.inc.php:
Find
"FORUMS_TOPICS_PAGES" => $pages,
Replace
'FORUMS_TOPICS_PAGES' => sed_build_pagnav($totaltopics, $cfg['maxtopicsperpage'], "forums.php?m=topics&s=$s&o=$o&w=$w&d=", $d),
Find
$row['ft_pages'] = $L['Pages'].":";
for ($a = 1; $a <= $row['ft_maxpages']; $a++)
{
$row['ft_pages'] .= (is_int($a/5) || $a<10 || $a==$row['ft_maxpages']) ? " <a href=\"".$row['ft_url']."&d=".($a-1) * $cfg['maxtopicsperpage']."\">".$a."</a>" : '';
}
Replace
$row['ft_pages'] = sed_build_pagnav($row['ft_postcount'], $cfg['maxtopicsperpage'], $row['ft_url'].'&d=', 0, true);
5. Edit system/core/list/list.inc.php:
Find
Complete
$t->assign(array(
"LIST_PAGETITLE" => $catpath,
'LIST_PAGES' => sed_build_pagnav($totallines, $cfg['maxrowsperpage'], "list.php?c=$c&s=$s&w=$w&o=$o&p=$p&d=", $d),
Use {LIST_PAGES} in your skin's list.tpl.
6. Edit system/core/pm/pm.inc.php:
Find
Complete
$t-> assign(array(
"PM_PAGETITLE" => $title,
'PM_PAGES' => sed_build_pagnav($totallines, $cfg['maxrowsperpage'], "pm.php?f=$f&d=", $d),
Use {PM_PAGES} in your skin's pm.tpl.
7. Edit system/core/users/users.inc.php:
Find
Complete
$t-> assign(array(
"USERS_TITLE" => $title,
'USERS_PAGES' => sed_build_pagnav($totalusers, $cfg['maxusersperpage'], "users.php?f=$f&s=$s&w=$w&d=", $d),
Use {USERS_PAGES} in your skin's users.tpl.
Have fun!
1. Edit your system/functions.php, add the following function to the bottom of the file:
PHP Code:
function sed_build_pagnav($totalitems, $perpage, $address, $pagenumber, $disable_pageof = false)
{
// CONFIG
$L['First'] = 'First'; // First
$L['Last'] = 'Last'; // Last
$L['page_of'] = 'Page %1$s of %2$s'; // Page of
$each_side = 3; // Links each side
// DO NOT EDIT BELOW
// Numbers
$totalpages = ceil($totalitems / $perpage);
$currentpage = floor($pagenumber / $perpage);
// Next/prev & first/last
if ($pagenumber > 0)
{
$prev_n = $pagenumber - $perpage;
if ($prev_n < 0) { $prev_n = 0; }
$prev = '<span class="pagenav_prev"><a href="'.$address.$prev_n.'"><</a></span>';
$first = '<span class="pagenav_first"><a href="'.$address.'0"><strong>«</strong> '.$L['First'].'</a></span>';
}
if (($pagenumber + $perpage) < $totalitems)
{
$next_n = $pagenumber + $perpage;
$next = '<span class="pagenav_next"><a href="'.$address.$next_n.'">></a></span>';
$last_n = ($totalpages-1)*$perpage;
$last = '<span class="pagenav_last"><a href="'.$address.$last_n.'">'.$L['Last'].' <strong>»</strong></a></span>';
}
// Rest
$i = 0;
$n = 0;
$pages = '';
$cur_left = $currentpage - $each_side;
$cur_right = $currentpage + $each_side + 1;
$passed = false;
while($i < $totalpages)
{
$mul = ($n % 2 == 0) ? 2 : 5;
// Current & each side
if(($i >= $cur_left && !$passed) || ($currentpage < 10 && !$passed))
{
// Left side
$start = ($cur_left <= 0) ? 0 : $cur_left;
for($j = $start; $j < $currentpage; $j++)
{
$k = $j * $perpage;
$pages .= '<span class="pagenav_pages"><a href="'.$address.$k.'">'.($j+1).'</a></span>';
}
// Current
$pages .= '<span class="pagenav_current">'.($currentpage+1).'</span>';
// Right side
$stop = ($cur_right > $totalpages) ? $totalpages : $cur_right;
for($j = $currentpage + 1; $j < $stop; $j++)
{
$k = $j * $perpage;
$pages .= '<span class="pagenav_pages"><a href="'.$address.$k.'">'.($j+1).'</a></span>';
}
// Move pointer if needed
if($cur_right + 1 > $i * $mul) $n++;
$passed = true;
}
else
{
$k = $i * $perpage;
$pages .= '<span class="pagenav_pages"><a href="'.$address.$k.'">'.($i+1).'</a></span>';
}
if($i < 10) $i = 10;
else $i = $i * $mul;
$n++;
}
// Result
if(!$disable_pageof) $pagnav = '<span class="pagenav_title">'.sprintf($L['page_of'], $currentpage+1, $totalpages).'</span>: ';
$pagnav .= $first;
$pagnav .= $prev;
$pagnav .= $pages;
$pagnav .= $next;
$pagnav .= $last;
return $pagnav;
}
You may want to change values in the CONFIG section before you use it.
2. Edit your skin's CSS and design the outlook for your pagination. Here is an example:
CSS Code:
.pagenav_title, .pagenav_first, .pagenav_last {
margin:0px 2px 0px 2px;
padding:0px 2px 0px 2px;
}
.pagenav_pages, .pagenav_prev, .pagenav_next, .pagenav_current{
margin:0px 2px 0px 2px;
padding:0px 2px 0px 2px;
font-weight: bold;
}
.pagenav_pages a, .pagenav_first a, .pagenav_last a, .pagenav_prev a, .pagenav_next a {
text-decoration:none;
}
.pagenav_current {
text-decoration:underline;
font-weight:normal;
}
3. Edit system/core/forums/forums.posts.inc.php:
Find
PHP Code:
"FORUMS_POSTS_PAGES" => $pages,
Replace:
PHP Code:
'FORUMS_POSTS_PAGES' => sed_build_pagnav($totalposts, $cfg['maxtopicsperpage'], "forums.php?m=posts&q=$q&d=", $d),
And use {FORUMS_POSTS_PAGES} in your skin's forums.posts.tpl.
4. Edit system/core/forums/forums.topics.inc.php:
Find
PHP Code:
"FORUMS_TOPICS_PAGES" => $pages,
Replace
PHP Code:
'FORUMS_TOPICS_PAGES' => sed_build_pagnav($totaltopics, $cfg['maxtopicsperpage'], "forums.php?m=topics&s=$s&o=$o&w=$w&d=", $d),
Find
PHP Code:
$row['ft_pages'] = $L['Pages'].":";
for ($a = 1; $a <= $row['ft_maxpages']; $a++)
{
$row['ft_pages'] .= (is_int($a/5) || $a<10 || $a==$row['ft_maxpages']) ? " <a href=\"".$row['ft_url']."&d=".($a-1) * $cfg['maxtopicsperpage']."\">".$a."</a>" : '';
}
Replace
PHP Code:
$row['ft_pages'] = sed_build_pagnav($row['ft_postcount'], $cfg['maxtopicsperpage'], $row['ft_url'].'&d=', 0, true);
5. Edit system/core/list/list.inc.php:
Find
PHP Code:
Complete
PHP Code:
$t->assign(array(
"LIST_PAGETITLE" => $catpath,
'LIST_PAGES' => sed_build_pagnav($totallines, $cfg['maxrowsperpage'], "list.php?c=$c&s=$s&w=$w&o=$o&p=$p&d=", $d),
Use {LIST_PAGES} in your skin's list.tpl.
6. Edit system/core/pm/pm.inc.php:
Find
PHP Code:
Complete
PHP Code:
$t-> assign(array(
"PM_PAGETITLE" => $title,
'PM_PAGES' => sed_build_pagnav($totallines, $cfg['maxrowsperpage'], "pm.php?f=$f&d=", $d),
Use {PM_PAGES} in your skin's pm.tpl.
7. Edit system/core/users/users.inc.php:
Find
PHP Code:
Complete
PHP Code:
$t-> assign(array(
"USERS_TITLE" => $title,
'USERS_PAGES' => sed_build_pagnav($totalusers, $cfg['maxusersperpage'], "users.php?f=$f&s=$s&w=$w&d=", $d),
Use {USERS_PAGES} in your skin's users.tpl.
Have fun!


























