I haven't seen this discussed elsewhere, but I may have missed it. I'm sure someone has done this before.
My client has about 20 categories to which he actively assigns new posts. We want to display links to the three most recent categories in a menu in the header. That is, suppose your five most recent posts (in order from oldest to newest) are:
Post 1 -- Category A
Post 2 -- Category B
Post 3 -- Category C
Post 4 -- Category D
Post 5 -- Category D (again)
... we would want links to Categories D, C, and B to be displayed (no duplicate link for D).
Currently, my client assigns posts to only one category. I don't think he has any plans to change that, so I don't need to worry about the case when a post is assigned to several categories.
I've come up with a solution that will work involving a second loop, a post-counting counting array, and a bunch of if/else conditions to identify the categories I need. But that feels like using a chain saw for something better suited for a pocket knife. Is there a simple and lightweight way to do this?