These are not instructions on teaching any specific trick, just a general summary of the principles which apply to teaching both essential good manners and silly tricks.
Step 1: Rewards and punishments
To mold behavior you need rewards and punishments. Rewards include food, of course, but also an affectionate scratch or belly rub, a friendly word ("good dog"), throwing a ball, or anything else the dog will enjoy.
Punishment can be as simple as looking away and ignoring the little nudges your dog gives you as it begs for a pat on the head. This is the best way to control a puppy who gets over excited while playing. Removing a favorite toy is another humane punishment, but on occasion harsher treatment is necessary: a sharp "NO!" a loud clap right next to the ears, a time out, or in rare cases a symbolic slap on the nose or rear end. The hit should NEVER hurt -- your goal is to teach, not to extract revenge, which is why many dog training books will refer to punishment as "negative reinforcement." The word punishment sounds too angry.
Reward good behavior and punish the bad. This seems obvious, but very few dog owners obey this rule. Here are a few examples:
Dog aren't allowed in children's playgrounds, so they are often tied up outside the gates to wait while the children play. Some dogs will wine, bark or howl till their masters come back. A few years back I witnessed a terrier with a very well-trained human. The dog would bark, the human would come running. The woman would pet the dog and speak to it in soft, reassuring tones. The dog would wag its tail happily, then start yipping the minute she stepped away. This routine was repeated about a dozen times, till finally she couldn't even turn her head towards her child. She left the playground, her kid crying to stay longer, the dog jauntily trotting by her side. I never saw them again but I had learned my lesson: never reward bad behavior. Some tender-hearted animal lovers might argue that the dog was genuinely anxious (i.e. he wasn't being "bad"), but the facts remain: if you don't want a certain behavior you must discourage it. Rewarding it will just make matters worse.
The first time I tied up my beagle he started to bark. Beagles are very vocal, very expressive, and very loud. Mine can put real pathos into his howls, and that day he treated the whole neighborhood to a heart wrenching performance worthy of "La Tosca." I did go to him, but instead of love and sympathy he got a sharp word, a loud clap near his ear and then the view of my back as I strode off. Body language is important. Pretty soon the sight of me stalking towards him in (mock) anger was enough to make him stop barking. We didn't stay very long -- it was clear from their dirty looks that the other mothers considered me cruel -- but we returned every day and before the week was up my dog was cured. Now he can relax by the fence for hours, enjoying the fresh air and the adoring attention of all the children. I'll check up on him once and a while and give him a reward for being so good.
A barking dog is annoying, but when I was visiting some friends I had to cut our stay short when they were unwittingly training their dogs to attack my children. My friends had two large rescue dogs of indeterminate breed. The dogs would bark when strangers came into their home but would soon settle down -- if the strangers were adults. My two boys, aged seven and nine at the time, looked just like prey. The dogs circled around them barking and growling with their teeth bared as their master tried to reason with them. He explained to the dogs in an kind, reassuring voice that these children were friends. Only after one of the dogs lunged at my younger son, biting the boy's sweater right under his neck did their owner finally agree to lock them up. When their mistress came home she let them out. She had more authority over the dogs and felt sure she could make them behave: her tactic was to call them to her when they growled, where they were rewarded with caresses and the occasional treat. "Stop that!" she gently scolded, whenever her dog showed its teeth if a boy dared tiptoe by. Of course the dogs continued to threaten the children -- the dogs were never sharply and clearly reprimanded, instead they were being rewarded for their behavior with extra attention and affection. Bad behavior should always be followed immediately by negative consequences -- otherwise not only will the bad behavior continue, it will worsen.
There are some cases in which punishment should not be used: when you are training a dog to do a silly parlor trick this is a game you are playing with the dog and it should be fun for everyone. If the dog is slow to understand, chances are the trainer is to blame. Dogs don't mimic: if you stand on all fours and shake, for example, a child might imitate you but a dog will just stare like you've gone out of your mind. A dog won't understand either if you try to push it into a certain position. The dog sees the action -- you moving it around (probably against its will) -- not its final position. To train your dog you must first train yourself -- to communicate in a way the animal can understand.