Paging Bug

I found this interesting, so I'll share. There was a #bug in the code that decides how many pages of #blog posts there are. If there was an exact multiple of the max posts per page, there will be an extra, blank, page. Simply subtract one from the number of results:
$maxPage = intdiv($totalResults -1, $resultsPerPage);

Not complicated, but it took me a while to come up with this clean solution. No conditionals, it just works. For reference, this is the bit lower in the code for the older posts button:
if ($page <= $maxPage){ write the button }

Posted 31 Jan 2019 by Brian