When it comes to comedy there are a number of different levels. Understanding these levels should help your writing. These are the six basic levels.
Level 1: Scatological Humor. You'll not that as we go through these, there's a plus/minus to humor: The more specific the joke's target, the funnier the joke. However, that also means that a smaller crowd will get it. Body fluid jokes are pretty funny to anyone; that's why you see so many of them. Because almost everyone has experience with sex, urination, defecation, and flatulence, and because they are considered just a bit embarrassing and intimate, they make for some great comedy.
Level 2: Slapstick. Violence is, unfortunately, part of the human condition. At the same time it is deplorable and we all recognize that; no one wants to be the victim of violence himself no matter how tough they may act, and so it's very presence makes us nervous. This is why slapstick works; we understand that it is a way of dealing with a subject with which we are nervous and makes fun of it. Understand that, and you can make this work.
Level 3: Puns. Okay, now we start getting more specific. Puns are reliant on language; if you don't understand the language, you aren't going to get the joke. The best puns are those that make fun of the orginal in meaning, poking some fun at them. After that are the more absurd ones, that we know the original saying, but have nothing to do with it. This is an area to have fun with, but not too much or you will be tracked down and lynched.
Level 4: Parody. Parody has some issues with it. The problem is that it needs to be on target to work; a parody that is on the beam can be absolutely hilarious, but one that is even off a little will die horribly. Look at Mad Magazine or Saturday Night Live; the sections and sketches that work well kill, but there are also a lot of jokes that die horribly. A good humorist needs to keep that in mind, and not be afraid to try anything; yeah, you're going to fail miserably a lot, but when you succeed you are king of the world. At least until the next joke...
Level 5: Satire. Parody makes fun of a specific subject; satire attacks an entire society. This is one where you really need to know the subject or forget about it. Satire walks a very thin line between humor and boorish, and it's a very easy line to cross. "Gulliver's Travels" is the prime example here; you want to make fun of the target and be respected for it, especially when the target has some actual power. Satire is the power of education; it needs to teach what is wrong about a subject so that the problem can get corrected. This is why jesters were kept around; a good jester could warn the king when he was being too big the fool. By listening to the jester, a king could be more effective. However, keep in mind that the jester had some fatal occupational hazards before you decide to be a satirist.
Level 6: Dark Humor. This is the one that is so specific it does not always work. For those who do get it, it can be very biting, very nasty and very funny. This expresses are very fears and pokes fun at them in order to make it less threatening. These are the jokes about 1984 and Cthulhu, about Ayn Rand and religious governments. This makes satire look like a walk in the park. Keep in mind that, in order to be funny, someone has to get it; if you are the only getting the joke, then it probably isn't that funny, so go down a level or two.