or: the dangerousness of simple mathematics
I guess many people had this problem before and I think everybody managed to solve this quite similar. Anyways, just in case this is useful for anybody: here’s how I added a pagination to a site recently.
Given you have an array of products for example. Or maybe search results, a list of articles… something like that. Unfortunately they are too many to display them on a single page. Well, sure, you could but let’s be honest: that isn’t an option as the page would exceed its “scrollable-with-no-harm-to-scroll-fingers” length. And you don’t want to get sued by your visitors, right 
Ok, so you’re going to add a nice pagination to your site, so that everybody is happy.
What I found out to be a bit tricky was to calculate the actual number of pages. We need that number so that we know, how many page links we will show next to our current view.
Continue reading →