If you can learn how to write a fart, you're there.
That's a bit glib, but it gets to the central problem with writing humor: many things are only funny because the situation makes them funny.
By the way: My eleven-year-old self would like an apology from everyone who ever lectured him using the words "That is not funny..." He had historical precedent is on his side. It's in the genome, nothing I can do about it; farts were funny in ancient Sumer!
(Nephews take note.)
To drag this up a notch from the archaeology of bodily functions, I was listening to an NPR interview with the great Canadian humorist Stuart McLean the other night. In the interview, McLean refused the interviewer's polite entreaties to analyse his humor.
Somehow, when someone asks me how to write humor, or how I write humor, I can't bring myself to say "It's not my job to understand it, just to do it."
I want to understand it. Moreover, the teacher in me wants to be able to answer the question with something more than "Learn to write farts."
Exempting physical humor (which is almost impossible in written form) I see three common types of humor. It's really not that hard to be funny in real life, because almost all humor is physical, topical, anecdotal, or situational. The moments when you laugh so hard that you're literally ROTFL are usually a combination of all four.
(Someone keep an eye on the frog for me. Is it dead yet?)
If writing is supposed to be an honest reflection of our world, then most humor we write will be situational. Being funny in real life isn't that hard because it isn't about telling jokes, it's about a given moment when what happens is funny. Farce is another thing entirely, worthy of its own frog... er... blog post.
For the most part, writing humor is and will always be about creating "You just had to be there" moments between your characters and your readers. Some people can do this instinctively, what Stuart McLean called 'writing from the belly'. Some have to learn how to do it, and in order to do that, I'm afraid you're going to have to exploratory surgeries on some frogs.
Part of being a writer is examining our own lives and interactions, mining them for moments and ideas that will breathe life into our writing. In order to do that, we must take scalpel in hand and pull them apart at least a little.
Why was it funny when Aunt Bethany farted? If you accept that bodily functions aren't inherently funny, you're left with the incongruity, the surprise. Why was it a surprise? Because it was your prim Aunt Bethany? Because it was Thanksgiving dinner? Because she'd just told off your kid for doing the same thing?
If nothing else, watch a video or an episode of a good sitcom. Pick them apart and look at how they work. At first, you'll just be staring uncomprehendingly at the broken parts of a dead joke. Eventually, you'll start to see the function of each piece and how they fit together. Eventually, you'll be able to reassemble the joke, better, faster, stronger than before.
I guess you had to be there? Let me put you there...
In the meantime, don't tease the frogs.