July 7, 2006 at 4:09 pm
Some people were interested in seeing the code I used to create the pagination for WineLog, which was based on the style of pagination used on sites like Digg and Flickr. I’ve put together a little demo which should help out anyone who is trying to create the same effect on their site.

(digg-style pagination demo)
[...] I hope this helps those who were interested. Please post any questions or comments concerning the code at the Stranger Studios blog post on the demo. Thanks. [...]
Any simple way to integrate this into Wordpress? I’ve been trying but have run into a lot of error messages.
Hrmmm, this saves a hell out of my time. I’m planning to write similar like this. Thanks Jason!
Jason
(yes, i’m jason too)
[...] Paginate your site like-digg [...]
Nice, this is useful! I’ve ported a version to Perl, which I’ll email to you.
[...] Earlier in the year, I wrote a tutorial on how to create pagination similar to Digg’s. The article focused on the basic algorithm for displaying the pagination, and there was definitely some opportunity for improvement in its implementation. [...]
Great code!!!
I was tring to use it in my site, but the ” page nav buttons ” did not show up.
The listed iterms are fine. any hint?
BTW seems not work when I check the page source.
Thanks
Hi!
I have problem vith this script “undefined variable $page”!
So i add >>>if (isset($_GET['page'])){$page=$_GET['page'];}else{$page=0;}0)
$start = ($page – 1) * $limit;
……..
Regards
[...] La creación de esta plugin de paginación fue basada en la versión modular creada a partir de la original creada por strangerstudios.com. [...]
[...] This is ASP based pagination script, similiar to Digg.com pagination. The credit goes to Jason Coleman who written this script in PHP and I simply converted this into ASP. I have attached screenshot this will help you to see how it looks like. [...]
[...] I’ve been on a bit of a digg kick lately and I like how they handle paging so I decided to create a GridView control that uses custom paging similar to digg’s. The algorithm is based on this post. As far as html output goes, this should be fairly close to the actual output on digg and I’m using digg’s stylesheet in the demo. [...]
Hey, great script!
One note for people working with php and not being an expert, I had a small issue come up where it thought the numbers were part of the variable. I had to change the code slightly…
FROM:
$pagination .= “1“;
$pagination .= “2“;
TO:
$pagination .= “1“;
$pagination .= “2“;
Brad, they look the same to me. Can you explain the change?
If I had more time I would take a look at the code to see what you were talking about.
Cool stuff!
Got any Javascript version of this?
Thanks so much to you digg, you are a sweet man. I am trying to use your pagination system on my website.It look so nice, that i am going to change all what i had.
One more again thanks…You can just see the system here http://www.icom7.com
Some people are finding out that you may have to declare the variables passed in through the URL at the top of your code. (my server settings allow me to just access them directly)
You can add some code like the following to the top:
$page = $_REQUEST['page'];
Rinse and repeat for any other variables you’re passing around.
Hi Jason,
I have not taken this live on my site yet, I am just testing at this
point…..
But, I have a question… I have a var, search, in a form that calls this page. The script seems to execute fine, but it is completely empty even when I make a selection that should yield ~150 results.
Any ideas on what I could be doing wrong?
Thanks,
Jim
Hi, Jim. I’d need to see more of your code to help you out. My guess is there is some error in your SQL query. Make sure that the variable passed by your form really has something in it. Do an “echo $search” at the top of the script. If you aren’t seeing what you should, make sure you are setting the variable (needed on some servers) like so “$search = $_REQUEST['search'];”.
Good luck. Feel free to email me for more help.
Hello again Jason,
The vars are being passed properly. I placed a print statement in the script to verify this.
My question is what var should have the search term in it?
I tried search to no avail….
Could someone please send me a reference of a simple page that impliments this script with just a few pictures on it. I’m really new to this stuff and can not figure it out. I want to use it on my site – imediadotcom.com
sorry, i also don’t use sql.
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.
I’m not as familiar with Movable Type and its plugins. You can hit up Mis-Algoritmos here:
http://www.mis-algoritmos.com/2007/05/27/digg-style-pagination-class/
btw, that’s an interesting class implementation. It’s pretty sweet. I know though that when I was first learning PHP, classes were almost always over kill for me and confused me a bit. If this is you, take a look at some of the older code.
However, if you are already familiar with classes and/or a PHP expert already who is looking to save time, take a look at that class and use it.
I am having troubles implementing the digg style pagination system into my project. http://www.superwebcamgirls.com can anyone help me with a simple more detailed code.
The only thing I had to add at the beginning was:
if(isset($_REQUEST["page"])) {
$page = $_REQUEST["page"];
} else if(isset($_POST["page"])) {
$page = $_POST["page"];
} else if(isset($_GET["page"])) {
$page = $_GET["page"];
}
after I made the connection to the DB.
You can see it at work:
http://www.axewar.com/topaxe.php5
Thanks for this excellent piece of script!! Easy to implement and works like a charm!
Mahesh,
Looks great on your site. Very nice site also, btw. I should probably add your code to the top of my implementation. It’s only needed if you don’t use the register_globals. However, if you do register globals, this code doesn’t hurt.
Sander, glad it worked out for you.
how to integrate like this :
Displaying 1 – 16 of 365 queries [Total 22 Pages]
thanks,
Kanchan
How to show in this pagination??
Showing from 1 to 20 from 200 queries.
I really want to use this script but not really understanding how you implement the code into the site. I’m a php newbie- please help!
In the modularized version of the function, diggstyle_function.txt, there is a typo on line 55. ($adjacents * 3) should be ($adjacents * 2).
Is anyone still offering help with this? I would really like to use this with my Zenphoto gallery. Please help!
Kanchan, if you are still interested email me (use contact form). I’ve done this on some of my projects and can try to get an example on this site.
Jason
Thank you very much. tried it and loved it. working perfect
Ubercool script, I made it work with jQuery at http://www.dealspost.com (scroll to the bottom). Only one glitch I have found: if you have a lot of records in the database (hundreds) and you set adjacents = 3 then on page 9 will dissappear link Next and pagination will not generate links to pages 10+ except for the last two pages. But if you change to adjacents=2 it works like a charm.
Thanks a lot for your work.
Joe
Script works perfect if I want to select everything from the table. But When I chose certain categories from the table, first page comes ok. but other pages are empty.
I used this query
$query = “SELECT * FROM $tablename WHERE country=’$country’ AND typeoffood=’$typeoffood’”;
Another thing is, the number of pages that is showing is for whole table because of this code I think:
$queryCount = ‘SELECT count(*) FROM ‘.$tablename;
I am very new to php. Can you help?
Am trying to use the pagination code but its not giving me any results. What am i missing. Nothing completly shows up. Please help me
firstly,this is good coding..
but i have some problem.the page is always shows this error :
Use of undefined constant num – assumed ‘num’
this is my coding:
$query = “SELECT COUNT(*) AS num FROM $tbl_name”;
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
did i do anything wrong??please help me..actually,i’m not very good in php..please help me..i need help coz this part is important to me..i need this ASAP..
Thanks..
excuse the trite question, but where I take the code in my db?
What exactly should I enter in this part of the code? “Place code to connect to your DB here.”
First, folks with DB or other app issues, I’m sorry I can’t help you more. If you have the budget, you can contact us (use link in top menu), and we can take a look at your code at our consulting prices.
Secondly, someone emailed me with some minor updates to the code and CSS that offer better scaling/resize support for IE browsers. The code on the demo site has been updated.
Thanks!
thanks to this code .
this is good coding.. I m implementing this code to my all sites that i had done..
Thanks a lot….
Wonderful pagination script , I used it already, thanks a lot.
Sir,
i impliment paging using your code.but now i am able to see links of all pages. but when i am clicking the corresponding page, i cant able to access the result.
only i got the result when the value of page=0. i think value of page is not coming properly.same thing i am using
$page = $_GET['page'];
please help me
You guys are great! thanks for this little tool. It really ease the work load