Sorted database with previous + next buttons

Hello,

I followed this post to do the previous and next buttons: Velo Tutorial: Creating Previous and Next Buttons for a Dynamic Item Page with Code | Help Center | Wix.com

But they don’t do it in any particular order. Is it possible to have it categorized by whatever page the user is on? E.g. If the person was on an office page, the next page would also be an office categorized page. Right now I have a dataset set up and linked it to dyanmic pages etc, with a field called “categories” that I want it to be organized by. (I also followed “https://www.wix.com/corvid/forum/community-discussion/next-previous-buttons” this but it didn’t seem to work.) I appreciate any help offered.

Thanks!