I found a smart< pagination script/code which I'd like to use in my serendipity installation. I tried to incorporate it in the include/functions_entries.inc.php, but this it work. Can anybody help me?
The code is written by Jorge and can be found at http://jorgev2.com/2007/05/19/smarty-and-pagination/
Here's a copy of his posting:
One task that always annoyed me has been pagination, it seems to come up in every project and every time I write some other solution for it. Well, I finally figure I’d just write a Smarty extension to take care of it.
This code is called like this:
{paginate count=30 curr=1 max=10 url=http://here.com/page-::PAGE::}
Where the count is the number of total items, curr is the current page, max is the maximum allowed number of displayed page links, and the url is the link to the other pages.
Anyway, below is some code, you can see it in action on KFO’s browse page (http://www.kittenfaceoff.com/browse)
<?php
$oTpl->register_function(‘paginate’, ’smarty_paginate’);
function smarty_paginate ($aParam) {
// {paginate count=30 curr=1 max=10 url=http://here.com/page-::PAGE::}
$nPageCnt = $aParam[‘count’];
$nCurrPage = $aParam[‘curr’];
$nMaxPage = $aParam[‘max’];
$sUrl = $aParam[‘url’];
$sOut = ”;
$bDrewDots = false;
if ($nPageCnt > $nMaxPage) {
if (1 > ($nCurrPage - ($nMaxPage /2))) {
$nStart = 1;
$nEnd = $nMaxPage;
} elseif ($nPageCnt < ($nCurrPage + ($nMaxPage /2))) {
$nStart = $nPageCnt - $nMaxPage;
$nEnd = $nPageCnt;
} else {
$nStart = $nCurrPage - ($nMaxPage / 2);
$nEnd = $nCurrPage + ($nMaxPage / 2);
}//if
} else {
$nStart = 1;
$nEnd = $nPageCnt;
}//if
for ($a = $nStart; $a <= $nEnd; $a++) {
if ($a == $nCurrPage)
$sOut .= “<span class=’current’>${a}</span>”;
else
$sOut .= “<a href=’” . str_replace(‘::PAGE::’, $a, $sUrl) . “‘ title=’Go to page ${a}’>${a}</a>”;
}//for
if ($nStart > 3) {
$sOut = “
<a href=’” . str_replace(‘::PAGE::’, 1, $sUrl) . “‘ title=’Go to page 1′>1</a>
<a href=’” . str_replace(‘::PAGE::’, 2, $sUrl) . “‘ title=’Go to page 2′>2</a>
<span>…</span>” . $sOut;
}//if
if ($nEnd < ($nPageCnt - 3)) {
$sOut .= “
<span>…</span>
<a href=’” . str_replace(‘::PAGE::’, $nPageCnt - 1, $sUrl) . “‘ title=’Go to page ” . ($nPageCnt - 1) . “‘>” . ($nPageCnt-1) . “</a>
<a href=’” . str_replace(‘::PAGE::’, $nPageCnt, $sUrl) . “‘ title=’Go to page ” .$nPageCnt . “‘>” .$nPageCnt . “</a>
” ;
// die($sOut);
}//if
if ($nCurrPage == 1)
$sOut = ‘<span class=”nextprev”>« Previous</span>’ . $sOut;
else
$sOut = ‘<a href=”‘ . str_replace(‘::PAGE::’, $nCurrPage - 1, $sUrl) . ‘” class=”nextprev” title=”Go to Previous Page”>« Previous</a>’ . $sOut;
if ($nCurrPage >= $nPageCnt)
$sOut .= ‘<span class=”nextprev”>Next »</span>’;
else
$sOut .= ‘<a href=”‘ . str_replace(‘::PAGE::’, $nCurrPage + 1, $sUrl) . ‘” class=”nextprev” title=”Go to Next Page”>Next »</a>’;
return $sOut;
}//smarty_pagenate
?>
Thanks in advance!
smarty and pagination
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: smarty and pagination
Hi!
Basically, there are two ways; you can use that obfuscated PHP code and put it inside your templates config.inc.php file; work with $serendipity['smarty'] instead of $smarty though.
The other, more convenient way, is to not rely on external pagination modifiers or plugins but work with the $footer_* variables (see http://www.s9y.org/102.html#A25) with which you can already do most things.
There's a german thread (http://board.s9y.org/viewtopic.php?t=1794) about this, too, which might give you some code clues...
HTH,
Garvin
Basically, there are two ways; you can use that obfuscated PHP code and put it inside your templates config.inc.php file; work with $serendipity['smarty'] instead of $smarty though.
The other, more convenient way, is to not rely on external pagination modifiers or plugins but work with the $footer_* variables (see http://www.s9y.org/102.html#A25) with which you can already do most things.
There's a german thread (http://board.s9y.org/viewtopic.php?t=1794) about this, too, which might give you some code clues...
HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Re:Re: smarty and pagination
Yes, I suspected the code to be a little bit obfuscated; I've already implemented the solution proposed in the german thread you mentioned, but there are two problems with it: First, I don't know how to limit the number of pages occuring in the list, second, the last page doesn't occur in that list - i.e. it shows just thirty pages when the standard pagination module shows a total of 31.
As I'm a newbie making the first steps on the php/smarty level I wasn't able to figure out the fixes to these problems yet; maybe you have a piece of advice which enables me to do that?
On the other hand, I'm still thinking of using Jorge's code - a bit of confused code won't be too harmful to my site, I suppose.
Generally, your hint at the serendipity CSS classes/Smarty Variables page will prove to be very useful - thank you very much!
veit
As I'm a newbie making the first steps on the php/smarty level I wasn't able to figure out the fixes to these problems yet; maybe you have a piece of advice which enables me to do that?
On the other hand, I'm still thinking of using Jorge's code - a bit of confused code won't be too harmful to my site, I suppose.
Generally, your hint at the serendipity CSS classes/Smarty Variables page will prove to be very useful - thank you very much!
veit