Advertisement:

Page Navigation

Aloittaja codenut, syyskuu 16, 2006, 04:55:20 IP

« edellinen - seuraava »

codenut

One of our users had requested if something like this would be possible for page navigation:

Pages: « < 1  ... 3 4 [5] 6 7  ... 27 > »

and since I didn't see anything that could mod the existing structure I thought I might as for it.
Steven Hodson
WinExtra
Blog: http://www.winextra.com
Forums: http://www.winextra.com/forums

Rudolf

You can do that very easily by modifying the constructPageIndex(); function.
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

klumy

good idea, especially the arrows < >>

codenut

Lainaus käyttäjältä: Rudolf - syyskuu 17, 2006, 02:38:53 AP
You can do that very easily by modifying the constructPageIndex(); function.

well considering my php skills are none existant I will have to wait until some enterprising modder decides to help out  ;D
Steven Hodson
WinExtra
Blog: http://www.winextra.com
Forums: http://www.winextra.com/forums

Rudolf

Here's the modified constructPageIndex(); function
Replace the one in Sources/Subs.php

// Constructs a page list.
// $pageindex = constructPageIndex($scripturl . '?board=' . $board, $_REQUEST['start'], $num_messages, $maxindex, true);
function constructPageIndex($base_url, &$start, $max_value, $num_per_page, $flexible_start = false)
{
global $modSettings;

// Save whether $start was less than 0 or not.
$start_invalid = $start < 0;

// Make sure $start is a proper variable - not less than 0.
if ($start_invalid)
$start = 0;
// Not greater than the upper bound.
elseif ($start >= $max_value)
$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
// And it has to be a multiple of $num_per_page!
else
$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));

// Wireless will need the protocol on the URL somewhere.
if (WIRELESS)
$base_url .= ';' . WIRELESS_PROTOCOL;

$base_link = '<a class="navPages" href="' . ($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%d') . '">%s</a> ';

// Compact pages is off or on?
if (empty($modSettings['compactTopicPagesEnable']))
{
// Show the left arrow.
$pageindex = $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, '«');

// Show all the pages.
$display_page = 1;
for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
$pageindex .= $start == $counter && !$start_invalid ? '<b>' . $display_page++ . '</b> ' : sprintf($base_link, $counter, $display_page++);

// Show the right arrow.
$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
if ($start != $counter - $max_value && !$start_invalid)
$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, '»');
}
else
{
// If they didn't enter an odd value, pretend they did.
$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;

// Show the left arrow.
$pageindex = $start == 0 ? ' ' : sprintf($base_link, 0, '«');
$pageindex .= $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, '&lt;');

// Show the first page. (>1< ... 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * $PageContiguous)
$pageindex .= sprintf($base_link, 0, '1');
else
$pageindex .= '';

// Show the ... after the first page.  (1 >...< 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * ($PageContiguous + 1))
$pageindex .= '<b> ... </b>';

// Show the pages before the current one. (1 ... >6 7< [8] 9 10 ... 15)
for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
if ($start >= $num_per_page * $nCont)
{
$tmpStart = $start - $num_per_page * $nCont;
$pageindex.= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
}

// Show the current page. (1 ... 6 7 >[8]< 9 10 ... 15)
if (!$start_invalid)
$pageindex .= '[<b>' . ($start / $num_per_page + 1) . '</b>] ';
else
$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);

// Show the pages after the current one... (1 ... 6 7 [8] >9 10< ... 15)
$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
if ($start + $num_per_page * $nCont <= $tmpMaxPages)
{
$tmpStart = $start + $num_per_page * $nCont;
$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
}

// Show the '...' part near the end. (1 ... 6 7 [8] 9 10 >...< 15)
if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
$pageindex .= '<b> ... </b>';

// Show the last number in the list. (1 ... 6 7 [8] 9 10 ... >15<)
if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);

// Show the right arrow.
$pageindex .= ($start + $num_per_page) > $max_value ? ' ' : sprintf($base_link, $start + $num_per_page, '&gt;');
$pageindex .= ($start + $num_per_page) > $max_value ? ' ' : sprintf($base_link, $tmpMaxPages, '»');
}

return $pageindex;
}


Check out my code in the Go to page topic to get a "go to page" box too.
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

codenut

Lainaus käyttäjältä: Rudolf - syyskuu 17, 2006, 12:43:59 IP
Here's the modified constructPageIndex(); function

Check out my code in the Go to page topic to get a "go to page" box too.

thank you very much that is greatly appreciated and worked like a charm. I'll head over and have a look at the Go to now :)
Steven Hodson
WinExtra
Blog: http://www.winextra.com
Forums: http://www.winextra.com/forums

Advertisement: