I did this yesterday and it's working as I want it to, but I'm unsatisfied with the code and feel like the arithmetic could be optimized a lot. my brain is dead right now so I thought I'd post it on here for ideas. let me explain some of my logic too. there are a couple of special cases in the code that might need some justification.
so if $range is set at 2 and we're on page 1, intuitively you would think it would display "1 2 3 … 20", but I figured that the first and last pages, since they're always displayed no matter what, shouldn't be considered in the $range calculation. so it would actually calculate the range as if we're on page 4 and display "1 2 3 4 5 6 … 20".
secondly, if you're on page 5, logically it would show "1 … 3 4 5 6 7 … 20", but in this case, displaying page 2 rather than an ellipsis gives more function in the same amount of space, so I elected to have it show "1 2 3 4 5 6 7 … 20", regardless of page 2 being technically outside of the range.
the php for all of this is kind of ridiculous so I'd appreciate comments.
functional example
php