How important is trendiness of the research one works on? I used to think that for research postdocs, faculty evaluate things like research potential. Now I think they still do, but they look a lot at whether the research topic interests the faculty. For example I have had a senior faculty member in some field (call it field A) tell me directly: "Field B is much sexier now than field A. Field A was very popular when I was doing my postdoc. Look at this researcher who did outstanding work in field A! Universities wouldn't hire him. He ended up getting something, but if he had worked in field B he would have done much better on the job market."

The lesson I took from this was: to succeed in academia it is not sufficient to do amazing research. It has to be amazing research in an area that interests people on the faculty of the universities you're applying to. For example, if University X has no homotopy theorists, but two representation theorists, then good results in representation theory would trump outstanding results in homotopy theory. 

When applying for postdocs, there is sometimes a question asking if applicants have "faculty contacts." I am also taking this as another piece of evidence. My impression is that a blank response looks worse than being able to say: "Professor Y is a potential collaborator." It seems pretty much necessary, to get any position at a given university, to do work in an area that interests some faculty members, so that they can be enthusiastic about an applicant.

A last example. When looking at MathJobs.org you can find postdocs in Europe for working in certain research groups. To get such a position, you need to fit your research into those areas. Suppose professor X is looking for a postdoc who works on problem 1. If two strong applicants apply, but another, by chance, does work more directly related to problem 1, then that applicant would be preferred.

Looking back at my time in grad school I think this is what I should have done: Make a list of all the academics in a given field and see what work they do. Look at who gets the big grants, and what topics the big conferences are in. Based on those criteria, determine who you want to do a postdoc under. Then decide who you want for a thesis adviser. Then steer your research to be interesting to those faculty members at the universities you would like to work in for your postdoc. In other words, direct your entire academic trajectory for a postdoc position. This way, five years later when it's time to apply for jobs, you'll find faculty members interested in your work, because your entire trajectory throughout grad school was towards that goal. This seems to be the best way to get postdoc offers.

In other words, I feel that there are many traps in academia that unsuspecting grad students or junior faculty can fall into and not get out of. Is my impression accurate?

On a more personal note: I have applied for a lot of postdocs and have gotten shortlisted a few times. But I have received zero offers. I suspect that other applicants fit the position better, not because my work wasn't good work (whatever that means), or any deficiencies in my application (though I could be wrong). I have no idea how to avoid these issues in the future besides the (admittedly rather extreme) plan I had proposed.
At least focus on your interests versus your advisors.  We get a lot of questions from weak reeds who just bend with the wind.  But at the end of the day, there's a huge investment of years by junior researchers in these projects.  Need to do something you want to do.  Exercise choice during advisor and project selection, stick up for yourself, etc.
Obviously it's a multivariable function (not just x and y, but some z's and w's floating in there).  So, you should look for something both marketable AND interesting.  While, it is unlikely that optimizing for one variable will optimize for the other, there likely are several areas where you can be both interested/skillful AND that are marketable.  Yes, absolutely you have to use your noggin when deciding this...and your advice to a younger you is relevant.
I would be wary of something that is trendy now if it has the seeds of changing soon.  String theory, nanoscience, machine learning, etc.  At least don't get involved in one of these rush areas if you aren't super interested in it (I don't believe the students who all come here and say they have a "passion" for machine learning--they have a passion for getting hired by Google.)  
I think often there is a lot of opportunity at field boundaries (and has been for decades).  "Material science" is the classic example.  If you can collaborate, it opens up possibilities and often you find others can't really compete as well in the border areas (are only able to work in the core). Personally I find that a lot of fun (and also doing applied work)...so it's not even a sales BS job for grants, like with some researchers.  I really like it.
It's probably good if you can package yourself as both a specialist and a fundamentalist.  I.e. I'm the math expert in some bizarre shale oil krieging junk.  But I also can find a home as a graph theory math person (I'm making this up...not sure if those are real things...but you get the idea).  Have some sexy thing like that specialty...but also make a department feel comfortable that you can teach basic classes and fit in with the core math department.
This is not to say there is no demand for people drilling down the center of the field.  But you better plan on being the best, then.  Really top notch.