Digg Style Pagination Class
Based on the modular version for the pagination, now I have created a version easier to implement, using classes for PHP version 4. The implementation is simple, is necessary to include the class with a require or an include. We defined basic properties for pagination such as an amount of elements to paginate, elements by page, page to which the element “page” will be sent, you need a CSS style and finally we generate the pagination to show it.
[php] include(ABSPATH.’/includes/pagination.class.php’); /* Now you can work with de pagination class */ [/php] The class.- Version 0.4.1 (2008-04-11)
- Added getOutput() function.
- Version 0.4 (2007-10-21)
- Added class next and prev to next and prev buttons.
- Bug fix
- Version 0.3.3 (2007-10-05)
- Possibility to set 0 as the current page (no page selected). Back and Next buttons won’t be shown.
- Version 0.3.2 (2007-09-19)
- Changed round to ceil (line 122)
Version 0.3.1(2007-08-23)Changed ceil to round (line 122)
- Version 0.3 (2007-07-10)
- Added the URL friendly functionality.
- Version 0.2 (2007-06-15)
- show an error and description if the function was called wrongly.
- Sends & instead of ? if the current file has vars in $_GET
- can change the name of the parameter ?page=
- there is no necessary to calculate in a manual way the pagination ($class->calculate()), is automatically when you show it the first time
- and others functionalities
- Version 0.1 (2007-05-27)
- First version
Dowload and unrar where you will work with the class. For the CSS, you can take one fromthis list.
If you forget a parameters to show or calculate the pagination. The class will show you a error to remember that. by example:
[php]$p=new pagination(); $p->show();[/php]the results:
It is necessary to specify the limit of items to show per page ($class->limit(10))
by default, the target of the pagination link is the same file where the paginations is showed. you can change it. using $class->target(file)
[php num=4]$p = new pagination; $p->items(1000); $p->limit(10); $p->target(”?foo=var”); $p->show();[/php]You can change the name of the parameter that brings the current page value. Using the $class->parameterName(”p”) you will see how the links changes the target to ?p=X instead of ?page=X
[php num=4]$p = new pagination; $p->items(1000); $p->limit(10); $p->currentPage(1); $p->parameterName(”p”); $p->show();[/php]Defining the pagination on its basic way, specifying an amount of items, limits of items by page, the pointed file by the pagination and the number of the present page.
[php]$p = new pagination; $p->Items(1000); $p->limit(5); $p->target(”paginator.php”); $p->currentPage(2); $p->show();[/php]Defining in 1 the amount of adjacent pages to the present page.
[php num=6]$p = new pagination; $p->Items(1000); $p->limit(5); $p->target(”paginator.php”); $p->currentPage(50); $p->adjacents(1); $p->show();[/php]Defining in 3 the amount of adjacent pages to the present page.
[php num=6]$p = new pagination; $p->Items(1000); $p->limit(5); $p->target(”paginator.php”); $p->currentPage(50); $p->adjacents(3); $p->show();[/php]Defining in 4 the amount of adjacent pages to the present page.
[php num=6]$p = new pagination; $p->Items(1000); $p->limit(5); $p->target(”paginator.php”); $p->currentPage(50); $p->adjacents(4); $p->show();[/php]Activating the functionality to show the pages amount.
[php num=6]$p = new pagination; $p->Items(1000); $p->limit(5); $p->target(”paginator.php”); $p->currentPage(6); $p->showCounter(true); $p->show();[/php]Changing the text of the navigation tags and removing the icons.
[php num=6-9]$p = new pagination; $p->Items(1000); $p->limit(5); $p->target(”paginator.php”); $p->currentPage(7); $p->nextLabel(’Siguiente‘);//changing next text $p->prevLabel(’Anterior‘);//changing previous text $p->nextIcon(”);//removing next icon $p->prevIcon(”);//removing previous icon $p->show();[/php]Removing the text of the navigation tags.
[php num=6,7]$p = new pagination; $p->Items(1000); $p->limit(5); $p->target(”paginator.php”); $p->currentPage(8); $p->nextLabel(”); $p->prevLabel(”); $p->show();[/php]Changing the icons of the navigation tags
[php num=6,7]$p = new pagination; $p->Items(1000); $p->limit(5); $p->target(”paginator.php”); $p->currentPage(9); $p->nextIcon(’►’); $p->prevIcon(’◄’); $p->show();[/php]Removing the text of the navigation tags and changing the icons.
[php num=6-9]$p = new pagination; $p->Items(1000); $p->limit(5); $p->target(”#”); $p->currentPage(10); $p->nextLabel(”);//removing next text $p->prevLabel(”);//removing previous text $p->nextIcon(’►’);//Changing the next icon $p->prevIcon(’◄’);//Changing the previous icon $p->show();[/php]Changing the div class (<div class=”class”>Pagination</div>) that surrounds the pagination (to manipulate many CSS styles)
[php num=6,8,11]$p = new pagination; $p->Items(1000); $p->limit(5); $p->target(”#”); $p->currentPage(11); $p->changeClass(”jogger”); $p->show(); $p->changeClass(”tres”); $p->show(); $p->currentPage(14); $p->changeClass(”meneame”); $p->show();[/php]To use the URL friendly, we need to execute the function $p->urlFriendly();. So we need to add to the $p->target(”#”); the placeholder % where we need the page numbers. If we need to change the placeholder, we can do it send it the desired char as parameter to the function $p->urlFriendly(’[...]‘);, and to the $p->target(”#[...]“);.
[php]$p = new pagination; $p->Items(1000); $p->limit(5); $p->currentPage(14); $p->urlFriendly(); $p->target(”#page/%/”);//#page/1/ $p->show(); $p->urlFriendly(’[...]‘); $p->target(”#pagina/[...]/”);//#pagina/1/ $p->show(); $p->urlFriendly(false); $p->target(”#”);//#page=1 $p->show(); [/php]51 Comments
Make A CommentComments RSS Feed TrackBack URL




May 27th, 2007 at 7:34 pm
[...] Algoritmos El acordeón que todos necesitamos… « WP Digg Style Pagination Plugin Digg Style Pagination Class [...]
May 27th, 2007 at 7:45 pm
How to create a digg and sabros.us style pagination with PHP
[Demo] [WP-Digg Style Pagination Plugin] [Some Styles for your pagination]
I made a few modifications to the sabros.us’s pagination script, inspired by the original created by strangerstudios.com, it needs a detail, turn it into a dynamic …
May 28th, 2007 at 3:45 pm
Oye, en el momento que haces click sobre una de las paginas, te refresca la página agregando la línea “?page=n” (parámetro por GET) pero si yo intento utilizarla dentro de una página que ya utiliza el GET hace falta que ponga el ampersan (&) y agregue “page=n”. De lo contrario no se podrá utilizar en páginas que ya tengan parámetros.
May 31st, 2007 at 7:54 am
@JL de hecho olvidé ese punto, le adicionaré ese detalle.
June 1st, 2007 at 8:06 pm
[...] If you wish to use the pagination in some of your systems programmed by own account you can use the Digg Style Pagination Class. A version easier to implement, using classes for PHP version 4. The implementation is simple, is [...]
June 6th, 2007 at 9:19 am
Hi,
A question…..
How can we change the value of parameter that brings the current page value ?
E.G :
Instead of using, page=1, page=2…..page=n……
I would like to use page=20, page=40,page=60,page=80….
(the query is too complicated to change so this is the only way to display each items….)
thanks for the answer
June 6th, 2007 at 1:24 pm
@LM you can add $id *= 10; to the get_pagenum function:
[php num=2]function get_pagenum_link($id){
$id *= 10;
if(strpos($this->target,’?')===false)
return “$this->target?$this->parameterName=$id”;
else
return “$this->target&$this->parameterName=$id”;
}[/php]
June 7th, 2007 at 1:45 am
Great !
Thanks.
I get another trouble….
Well, it’s working perfectly with the id incremented… but the pagination is still frozen on the page 1 even if you click on page 2,3,4,5,6……,n
and of course the button Next and previous doesn’t work…….
Any idea ????
Muchas gracias….
June 7th, 2007 at 10:08 am
@LM
ok, I’m understand that. I will try to find a solution to your problem.The $_GET['page'] value for $class->currentPage() value, you need divide it by 10.
[php num=2]if(isset($_GET['page'])){
$page = $_GET['page'] / 10;
$p->currentPage($page);
}else
$p->currentPage(2);[/php]
June 7th, 2007 at 10:51 am
Thanks….
Where Do I need to modify in the pagination.class.php ?
June 7th, 2007 at 12:34 pm
@LM You don’t need to modify the pagination.class.php (only this). It only need to call the currentPage function with a value divided by 10.
[php num=4-8]$p = new pagination;
$p->items(1000);
$p->limit(10);
if(isset($_GET['page'])){
$page = $_GET['page'] / 10;
$p->currentPage($page);
}else
$p->currentPage(1);
$p->show();[/php]
June 8th, 2007 at 4:30 am
Great !!
it works goods….
Thanks
June 10th, 2007 at 3:19 am
[...] Mis Algoritmos Hi
« Digg Style Pagination Class [...]
June 24th, 2007 at 8:51 am
Hey,
I’m getting an error with the include of the pagination.class.php (it works only in the same folder)
Error:
“Fatal error: Cannot instantiate non-existent class: pagination in……”
is there something i need to add in the pagination.class.php to solve that?
tnx
June 24th, 2007 at 11:50 am
“Fatal error: Cannot instantiate non-existent class: pagination in……”
You need to include the class.
July 25th, 2007 at 3:21 am
I absolutely adore this Digg style pagination! Thank you, so much.
However, tonight I installed Davide Pozza’s Global Translator plugin and whenever I click over to an auto-translated page it wreaks havoc on my pagination. Any idea what I need to tweak to keep this from happening?
July 26th, 2007 at 10:19 am
Line 122 reads:
$lastpage = ceil($this->total_pages/$this->limit);
Using ceil you often get an extra blank page at the end. I changed it to
$lastpage = round($this->total_pages/$this->limit);
And it works perfectly.
August 14th, 2007 at 7:45 am
Victor,
I find your pagination class adorable! I am a newbie in php and it seems I can’t get it working :~(
I have a project for which I coded other kind of pagination (every single page number displays, no matter how many results there are!) which didn’t suit my needs. Now I tried to fire up your navigation class but it doesn’t work for me. I don’t know how can I call it the right way because it always displays my first 10 rows from a database and nothing happens. Can you propose a solution maybe? How does your class know what rows it needs to displays when some other page from your pagination class is called?
August 16th, 2007 at 7:53 pm
I got the class working for general test purposes, but need help configuring it to friendly urls. Say the address is http://www.mysite.com/archive/site-news If they click the 2nd page it takes them to http://www.mysite.com/archive/site-news?page=2 but I want it to read http://www.mysite.com/archive/site-news/2 Can someone help with this?
August 16th, 2007 at 11:45 pm
Well I sort of got it to work, I used:
$p->urlFriendly();
$p->target(’%');
But this only works when the ending ‘/’ is on the url. There has to be a way that works for both, right?
August 17th, 2007 at 7:07 pm
[php]$p->urlFriendly(’[...]‘);
$p->target(”http://mysite.com/archive/site-news/[...]/”);[/php]
August 18th, 2007 at 2:20 am
Thank you very much, you have an awesome class and thanks for sharing and helping so many!!
August 19th, 2007 at 4:36 am
“Line 122 reads:
$lastpage = ceil($this->total_pages/$this->limit);
Using ceil you often get an extra blank page at the end. I changed it to
$lastpage = round($this->total_pages/$this->limit);
And it works perfectly.”
$lastpage = floor($this->total_pages/$this->limit);
works better
August 21st, 2007 at 7:03 am
Thanks verymatch for this paging class!
August 30th, 2007 at 2:51 pm
I’ve got the script mostly working but I’m getting hung up on one aspect. With $p->limit(10) queries that return 15 or more rows work perfectly, however on queries that return less than 15 rows the pagination is not displayed. I’d expect that to happen with less than 10 rows only.
Am I doing something wrong, or do I need to adjust something within the class?
Thanks!
G
September 1st, 2007 at 11:26 pm
The digg style solution here is great. Do you know how to incorporate this into Movable Type 4? I see that you have a Wordpress solution. It’d be great if this could also work in MT4. Thanks.
September 2nd, 2007 at 9:34 am
This is great. Que excellente.
This class implementation looks great, and the way to go for folks comfortable with classes.
What plugin are you using to show code in your posts? I’m looking for a good one.
September 4th, 2007 at 7:04 am
Hola @Monsef, ¿Que version del plugin estas utilizando?Este problema fue solucionado en la última version de la classe (la 0.3.1). Intenta descargandola, si siguen los problemas, me dejas un mensaje
@Alex: Maybe
Hi Jason Coleman I use the Exec-PHP Plugin.
September 9th, 2007 at 1:07 pm
[...] pagination class [...]
September 10th, 2007 at 3:18 pm
Nice class.
I also found an issue when dealing with the last page. For example, if I have 21 items, with a limit of 10 items per page, I should get 3 pages.
However, I am only getting 2 pages.
Looking at the code, you have a function called round, this only rounds up if the number is above .5. So it’ll round up correctly if you have 25 items, to show 3 pages. But if 21 items, only gives 2 pages.
I changed the function from “round” to “ceil” to round up to the next integer and now it works.
http://www.php.net/manual/en/function.ceil.php
September 11th, 2007 at 10:53 pm
hmm @Mike Grishaver which is the solution? =S
September 11th, 2007 at 11:42 pm
Hey Victor, I wasted over an hour already trying to figure out how to install your pagination plugin… Wordpress became the #1 blogging platform due to simplicity and ease of use, your plugin is overly complicated, even ridiculously so.
Que quiere decir esto por ejemplo? (What does this mean?):
“Based on the modular version for the pagination, now I have created a version easier to implement, using classes for PHP version 4. The implementation is simple, is necessary to include the class with a require or an include. We defined basic properties for pagination such as an amount of elements to paginate, elements by page, page to which the element “page” will be sent, you need a CSS style and finally we generate the pagination to show it.”
WHAT? Have you read the paragraph? I don’t think YOU can make sense of it. Thank God that now it is “easier to implement”, I don’t want to imagine how complicated it was before.
Víctor entonces y en resumen, si tu intención es compartir el plugin, hazlo simple de verdad, it’s supposed to be a PLUG - IN, lo enchufas y listo. Este es una tesis camino a la maestría en filología digital.
KISS principle comes to mind…
Nos vemos!
September 12th, 2007 at 8:51 am
Hola
Hay mas error en tu classe , beuno 1 error no functiona correctamente con el FreindlyUrl , mustra paginas blancas he probado meter floor o ceil pero sgue iguale 3) cuando selectiona una pagina siempre se muesra la pagina 1 como selectionada asi que no coje la pagina selectionada si tenemos el urlRewriter activado , proba lo
si tienes alguna solucion por fa ayudanos
Gracias
September 12th, 2007 at 10:11 am
Uff, tienes razón y lo siento pero, no puedo darle gusto al mundo entero. Me contradije pero pues, no veo aún una manera mas simple de hacerlo.
Además, mucho ojo! Esto no es un plugin ¡ES UNA CLASE en todo su esplendor! su uso es SIMPLE: lo incluyes en tu scripts y te apoyas de ella para trabajar con alguna de tus aplicaciones. Jamás mencioné que esto fuera un plugin y tampoco que estuviera basado en otro plugin.
Si por alguna razón la paginación de consultas no fuese TU fuerte, intenté describir un ejemplo apoyándome de la clase =S
September 26th, 2007 at 12:23 pm
Any example how to use with MySQL queries?
Thnx.
September 26th, 2007 at 7:13 pm
yes @bahodir, you can read this
October 17th, 2007 at 3:11 am
[...] Aquí [...]
October 20th, 2007 at 9:22 am
[...] Digg style pagination class [...]
November 23rd, 2007 at 6:40 am
Thank you very much for your great script, works like a charm and easy to use. 5/5
November 24th, 2007 at 11:23 pm
need help
Hi…I am using your pagination class and I need your help. Pagination is working ok when I open the page first time but when I click on page links like 1,2,3,4 ….it says page can not be displayed. I am passing variables with data between pages using URL. When I put my cursor on these links 1,2,3,4,…etc, it doesn’t show variables are attached to the url string. like in status bar it shows “http://localhost/filename.php?page=2″. If I use another pagination it shows “http://localhost/filename.php?page=2Field=test1find=test2…”. Here field and find are variables and test1 and test2 are values given to the variables.Do I need to change some code in the pagination class? Thanks for your nice pagination.
November 25th, 2007 at 9:49 am
sorry another pagination is like “http://localhost/filename.php?page=2&Field=test1&find=test2″.
Thanks
November 25th, 2007 at 3:19 pm
Hi
I am able to pass the parameters with url and pagination is working fine but it doesn’t change the records. It just stays at page one and numbers at pagination get changed. Any help?
Thanks
November 26th, 2007 at 9:17 am
Hello…I am using limit 10 and your pagination is working fine but its showing results starting from 11(i.e. pagination link 1 starts from 11 to 20, pagination link 2 shows 21 to 30 and so on) and the last page is blank. I tried Floor or round at line 122 but it doesn’t help me. I need your help.
thanks
December 11th, 2007 at 6:46 am
Same to me.
I have 25 limit. And I have one blank page at last, chage to “round” or “floor” I dont get last results.
December 28th, 2007 at 12:51 pm
I need Example very simple … Can you do That ?
(use select of table name of database)
Plz ….
I watting You ..
January 18th, 2008 at 11:27 am
On line 148 of your class, it reads:
—————————–8page adjacents * 2)){
—————————–8<—————————–
I got a result, with 20 pages, on the 4th page, with something like:
< 1 2 … 3 4 5 (etc)
In order to solve this, change the “if” statement to:
—————————–8page adjacents * 2)){
—————————–8<—————————–
Other than that, excelent job!
January 19th, 2008 at 5:26 am
Hi, Thankyou for the class.
I made a modification to one function in your class in order for it to be xhtml compliant since I had problems getting it validated. Basically I added htmlspecialchars(). It now validates properly.
New function follows:
function get_pagenum_link($id){
if(strpos($this->target,’?')===false)
if($this->urlF)
return str_replace($this->urlF,$id,$this->target);
else
return “$this->target?$this->parameterName=$id”;
else
return htmlspecialchars(”$this->target&$this->parameterName=$id”);
}
February 7th, 2008 at 11:34 pm
Did I tell you, your code simply rocks.. I was waiting for this kind of pagination class and finally found it
February 12th, 2008 at 10:04 am
[...] įvairiausių šio kodo variacijų, tačiau siūlau rinktis paprastesnį. Galimi du instaliavimo variantai, arba jums teks šitą [...]
March 4th, 2008 at 10:22 am
Thanks for this script
April 9th, 2008 at 12:46 pm
muy bueno lo tuyo!