0

I have a bit of a tricky one. I can figure out how to do back, previous, and next links for a specific taxonomy term, what I can't figure out is how to specify which term the user started viewing posts from.

I have taxonomy term archive pages that list posts for a given term. The user can click on a post and view that post. Basic stuff. The problem is when a particular post belongs to more than one term. Say it belongs to term A and term B. They click on the post while browsing term B. The back, next, and previous links at the bottom should correspond to term B, the term that referred them to the post page.

How do I determine which term the user was browsing in order to set up the links properly?

(Yes, I have googled this quite a bit. I found another post from nearly 5 years ago with the exact same situation, but no answer. Maybe it's just not possible. Custom Taxonomies: Multiple Hierarchical Permailnks For A Single Post + Prev/Next Links )

Thanks!

  • A general note that implementing this means that full page caching of posts will cause problems, as the first user to do this will get cached, leading to incorrect results when other users visit that page from a different term. This is because all of them share the same URL – Tom J Nowell Apr 23 '18 at 14:04
  • So basically, this is really not something I should try to do at all. – Mattaton Apr 23 '18 at 17:58
  • I wouldn't recommend it, but perhaps there are alternatives, e.g. showing the posts in JS in the archive, which sidesteps the URL issue. Also keep in mind that when the post is shared the referrer is not, so linked users won't see the same previous or next posts – Tom J Nowell Apr 23 '18 at 18:45
0

HTTP and therefor web pages do not have any context, which is what you basically need, and only browsers can store context. You can add the context on the PHP side in a cookie, add to the page some JS code that inspects the cookie and based on it sets the actual url for the links you want to have.

for the benefit of people that do not have JS enabled, or google, set some "default" URL values there.

  • Yeah, I thought about storing it in a session or cookie. I'm exploring other, simpler options. Probably end up just leaving off that navigation. Thanks! – Mattaton Apr 23 '18 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.