How to: Post Navigation with multiple Categories?


(Nathan Snyder) #1

We’ve been relying on the Smarter Navigation plugin to allow our Post Navigation (previous and next buttons) to select the other posts in the same category as the current page. It’s the only thing that seems to work for this.

However, it doesn’t work at all if the post has more than one category. How can we control Post Navigation on pages with multiple categories like this?

Thanks, we’ve been collectively looking for a solution for almost 10 years to this problem, I think!


(Leland Fiegel) #2

Put yourself in the plugin’s shoes. How would it “prioritize” which category you actually want to navigate through, presuming it could only be one? Would you be willing to specify it for each post with multiple categories? Would you be okay with it picking based on something arbitrary, like alphabetical order? A master priority list?

Some of these solutions can lead to more complications. For example, if you’re specifying the prioritized category for individual posts, a user could potentially be navigating through an unrelated category after two clicks from the original post.

Personally, I think the best solution is exactly how it works now: not work at all if multiple categories are selected. This encourages you to select a single category per post.

The simplest answer is to strictly limit your posts to a single category. Use tags or a custom taxonomy for additional organization of content, if necessary.


(Nathan Snyder) #3

I’m not finding fault with the plugin, I’m asking how to solve the problem with or without the plugin. I only mentioned the plugin as a reference point, so someone wouldn’t suggest it to me (because it doesn’t solve the problem).

Certainly, there must be people out there who’ve found a solution because it is absolutely necessary for several applications. For example…

Let’s say you want only “Front Page News” items to show up on the front page News section, but you want them also to be navigable so that once a person clicks through, they can go to the next news item without having to return to the front page. This is a standard sort of thing. Those Front Page News items might also need to be listed in a different category like Exhibitions or New Products, etc. It’s not sufficient or efficient to tell a client they have to make duplicate pages just to put one post in multiple categories.

I already discussed this on the Wordpress StackExchange around this time last year and someone there said he developed a solution, but I could not get it to work for the life of me. He was kind enough to give me the code, but it did not work. I plan to revisit that soon and see if I can get it to work, but since I found this new forum, I figured I would ask people here.


(Leland Fiegel) #4

Would you mind sharing that here? I’m trying to figure out how you’d expect a solution like this to work, which is what I was trying to gauge from this series of questions:


(Nathan Snyder) #5

[quote=“leland, post:4, topic:1548, full:true”]Would you mind sharing that here? I’m trying to figure out how you’d expect a solution like this to work, which is what I was trying to gauge from this series of questions
[/quote]

It’s probably more than you ever wanted to think about, but here it is: http://wordpress.stackexchange.com/questions/191938/echo-one-category-as-title-when-post-has-multiple-categories

I was trying to be brief so as not to scare people away who might recognize the problem and have a solution already. Long-windedness tends to send people packing.


(Leland Fiegel) #6

Ha, yeah…I can’t make much sense of that.

The solution is really dependent on your expectation of how it should work though. This is not the type of problem with an obvious, straightforward “fix.”

I’ll ask again:


(Nathan Snyder) #7

Well, the reason I linked that stackexchange page was because all of the prioritization options are pretty much covered in the top answer which has a green checkmark. The problem with the plugin I’m using is two-fold: (1) it doesn’t work with multiple categories, (2) it doesn’t work AT ALL if a user shares a link of the page via email or if someone visits the page from a Google search because there is no referrer for the plugin to determine the category in these instances.

So, the ways I would want to prioritize would have to be a combination of the considerations offered in the StackExchange answer. His solution was to:

  • add a special parameter to our URL which will serve as referrer
  • add a referrer to the post links via the post_link filter.
  • add a the query arg ref so Wordpress can read that info from the URL
  • check if the single post was a referred post, get the value from the URL and use that info to display the correct category name

Like I said, it seemed logical, but I couldn’t get it to work. Maybe I need to try again. I understand code a little better now.