This looks like something similar, you will have to tweak it to look how you want it to.
But that's a standard thing.
The code you want, someone may have.
But it is for a different source, so will need tweaking.
Anyway here is the link.
http://www.sanwebe.com/2011/05/php-pagination-function