When I first started playing guitar, I learned some of the standard open chords, such as E, A, C, G, A minor, E minor. But when trying to write my first songs, I had no idea which chords to use, or why, and how to make them work together.
What helped me most was learning the 'harmonized major scale'. Each key has a set of chords which are native to that key, and are based on each scale degree of that key. These are the chords generally used in writing songs in that key. Sure, they can then be embellished with added notes such as 9ths, 11ths or 13ths, but the base chord, be it a major or minor, remains the same. Many songs have chords which depart from this 'diatonic' formula, and we'll get into how to do that in another lesson.
Each chord only contains notes within the C major scale. I'm showing 4 note chords here, constructed with the tonic, third, fifth, and seventh (1-3-5-7), but when writing, the 7th is often left out, especially for rock tunes:
Here's the formula for applying this to any other key to get it's diatonic chords. Remember the formula for the major scale, too. It's W-W-H-W-W-W-H where W=whole step, and H=half step:
I........Major or Major 7th
II.......Minor or Minor 7th
III......Minor or Minor 7th
IV.......Major or Major 7th
V........Major or Dominant 7th
VI.......Minor or Minor 7th
VII......Diminished or Minor 7th flat 5
Learn to play the harmonized major scale in all of your favorite keys, and you'll gain a great understanding of which chords belong to which keys, which chords you can use when writing 'diatonically' in a key, and how to more easily identify which key your favorite song is in.