Links not directing properly, fixed with a loop

The Prev and Next links weren't directing properly on the live server.
Encompassed them in a loop and updated the functions.