Quote History Quoted:
Drop the aperture down to f16. Shrinking the aperture (the numbers go up the smaller it gets) controls depth of field, or the amount of focus you get. Experiment with that.
Focus on the first 1/3 of the subject, in this case, probably somewhere along the barrel or magazine. You can also back up a bit and that can help with the depth of field, then crop in later.
View Quote
Let me expand on this a bit.
Depth of field, or in other words, how much of your picture is in focus is dependent on 3 (or 4) variables, depending on who you ask.
1) aperture
2) focal length
3) distance to subject
4) sensor size (compact, crop, full frame, etc)
As the great and honorable Durka mentioned, closing down the aperture does increase the available depth of field. Focusing about 1/3 into the part you want focused is also true. But, he didn't really explain distance to subject. If you're close up on a subject, the aperture will never be enough to give you a full subject in focus. If you're far enough away, you'll get plenty in focus even with a wide aperture. This is where stuff like focus stacking and other crazy things comes into play. Focal length is a factor as well. The shorter the focal length, the greater the depth of field for a given aperture and distance to subject. Longer lenses compress the scene and give less apparent depth of field.
Also something to keep in mind is your subject doesn't need to be ALL in focus for the picture to work, often using shallow focus to draw attention is an effective method.