Pagination
Wednesday, February 11th 2009 — Programming
I decided to add paging to my blog the other day, and considered the different ways one could do so. The most common way is just to start at page 1, then after every X entries start a new page until you have pages for all your entries. I didn't like this option because it would mean that every time I added an entry, all the older entries would be "pushed down" one step on the pages, so the last entry on page 1 would then be the first entry on page 2. Why is this bad? Well, imagine if you searched for something on Google, and it linked to page 5 on a blog. So you go there and you find that the content you searched for isn't there; it's been pushed down to page 7. This can be a nuisance. And so I wanted to come up with an alternative solution.
One way to do it would be to categorize the entries by date, and browse one month at a time or some such. The problem with this is that it will result in an uneven distribution of entries across the pages. Instead, I decided to go with a variation of the solution I mentioned first.
My solution was to reverse the order of the pages. So page 1 would hold the X oldest entries; page 2 the subsequent X entries, and so forth. This way, page 5 will always hold the same entries, no matter how many entries you add. But there is one more thing to think of when doing this: you can't just show the last page by default. Say the last page is page 6, and it already has X entries. Now, if I add an entry, it will be on page 7, by itself. If I were to show page 7 by default, the front page would look pretty empty. So I added another, "magic" page (default if no page is specified) that shows the X most recent entries. And there you have it. Search-safe pagination.
P.S. It's worth mentioning that another reasonable option would be to turn off search-engine indexing of the pages through robots.txt or the robots meta tag, which would ensure that only results linking directly to the blog entry would show up.
Comments
Comment by ZcXAeVj
Added at 12:02 on Wednesday, March 3rd 2010
MAdYAQ
Comment by UzDfQrh
Added at 15:53 on Wednesday, April 14th 2010
zzxztVGs