Yet another solution to have lots of numbers on page
.
This solution should work with ugly url only.
This method does not depend on any module, but you need to know :
a. current page number
b. page count
c. pagination url parameter (e.g. 'pagenum')
Originally pagination on Products module looks like
<< < Page 444 of 1000 > >>
Pagination on template looks like
Code: Select all
{if isset($pagecount) && $pagecount gt 1}
{$firstlink} {$prevlink} {$pagetext} {$curpage} {$oftext} {$pagecount} {$nextlink} {$lastlink}
{/if}
We can make it look like this (444 is a current page)
1 90 190 290 390 400 410 420 430 440 441 442 443 444 445 446 447 448 458 468 478 488 498 598 698 798 1000
Colors just explains pagination pattern. And here is pagination template
Code: Select all
{if isset($pagecount) && $pagecount gt 1}
{if $curpage>1}
{assign var='tmp_link' value=$prevlink}
{else}
{assign var='tmp_link' value=$nextlink}
{/if}
{pagination link=$tmp_link param='page' max=$pagecount current=$curpage assign='temp' pattern='4,5,3' extreme='true'}
{foreach from=$temp key='page_nb' item='tmp'}
{if !empty($tmp)}
{$page_nb}
{else}
{$curpage}
{/if}
{' '};
{/foreach}
{/if}
You can see 3 comma separated numbers in pattern. First one corresponds to
4 pages that are next to each other, second -
5 pages that differ by 10 from each other, third -
3 pages that differ by 100 and so on. If parameter
extreme is not empty links to the first and the last page will be included if not present.
This is an UDT {
pagination} that assigns array of pagination links
Code: Select all
array($page_number => 'http://www ...', ... )
Current page has empty value. Most parameters are from standard pagination.
Code: Select all
/**
* Create array of pagination links
*
* @params string $params['link'] Mandatory. Href or complete link (href will be extracted).
* @params string $params['current'] Mandatory. Current page number
* @params string $params['max'] Mandatory. Max page number
* @params string $params['param'] Mandatory. Unique part of url param. e.g. 'pagenumber'
* @params string $params['assign'] Mandatory. Name of variable to assign result array($page_number=>'http://www... ', ...)
* @params string $params['pattern'] Pagination pattern default '10,10'.
* @params string $params['extreme'] Include first and last links
*
*/
$default_pattern = '10,10';
if (!empty($params['link']) &&
!empty($params['current']) &&
!empty($params['max']) &&
!empty($params['param']) &&
!empty($params['assign'])){
$link = preg_replace("/.*href=[\"\' ]*([^\"\']*).*/", '$1', $params['link']);
$link = html_entity_decode(trim(strip_tags($link))); //extract href
$param = trim($params['param']);
$assign = trim($params['assign']);
$max = intval($params['max']);
$current = intval($params['current']);
$params['pattern'] = (empty($params['pattern']))? $default_pattern : $params['pattern'];
$pattern = explode(',', trim($params['pattern']));
$extreme = (empty($params['extreme']))? FALSE : TRUE;
//debug_display($param);
if(strpos($link, $param.'=')){
$smarty = cms_utils::get_smarty();
$links = array();
$i_min = $i_max = $current;
foreach($pattern as $exp=>$count){
for($i = 1; $i <= $count; $i++){
$delta = pow(10, $exp);
if($i_min > ($delta + 1)){
$i_min -= $delta;
$links[$i_min] = htmlentities(preg_replace( "/$param=\d+/", $param.'='.$i_min, $link));
}
if($i_max < ($max - $delta)){
$i_max += $delta;
$links[$i_max] = htmlentities(preg_replace( "/$param=\d+/", $param.'='.$i_max, $link));
}
}
if ($extreme){
if($current != 1 && !isset($links[1])){
$links[1] = htmlentities(preg_replace( "/$param=\d+/", $param.'=1', $link));
}
if($current != $max && !isset($links[$max])){
$links[$max] = htmlentities(preg_replace( "/$param=\d+/", $param.'='.$max, $link));
}
}
$links[$current] = '';
}
ksort($links);
$smarty->assign($assign, $links);
}
}
EDIT: fixed broken UDT. Removed colors from code and template.