I've been trying to write music for a while now, and I just don't seem to get it at all. I'd say I'm a pretty good guitar player, maybe slightly above average, but songwriting has always seemed to escape me. I feel like I'm way to focused on individual aspects like writing a good riff or bassline or melody or whatever and I can't seem to grasp the whole picture. I can never get a feel for a general idea of a song as a whole, just little bits and pieces on one instrument, which usually leaves me stuck and hating whatever I came up with.

So, does anybody have any idea on things I can do to try to get around this? I'm pretty sure I can write some decent songs, but I need to be able to visualize where everything is going. Should I try learning other people's songs? And if so, what should I be focusing on?

Thanks in advance
Listen to as much different stuff as possible. Try and emulate the general feel of a song you love (this is NOT stealing music). You can even go as far as to take the chord progression and put your own spin on it.
Learning some theory never hurts, but forgetting it can be good too.
I wrote a song called 'Pessimism' recently, basing the structure loosely on 'I'll Follow The Sun' by The Beatles. It came out pretty nicely, and to me doesn't sound anything like The Beatles. All I did was take the general structural ideas, which led me onto using some of the same chord changes. Then I just went for it, wrote the whole thing in about an hour. It's in my sig if it helps at all
My Soundcloud
Always up for some C4C, been compared to Frank Turner, The Cure's Robert Smith and Bruce Springsteen so check out my stuff if you like the sound of that
Take some time aside and listen to a bunch of your favorite songs, but listen closely for how the song is put together rather than enjoy it. I do this all the time, always learning new things.

You don't even need to put time aside, next time you're listening to your iPod, stop on a good song and listen intently to it. Eventually you'll see a pattern. I don't know what genres you like but some great songwriters are:

Blink 182
Sum 41
Dream Theater
The Beatles
Chevelle (though not for lyrics, lyrics suck from these guys)
Jim Croce

Anyone let me know if I forgot any key ones!
Every now and then I write a riff, cut it up, move bits and pieces around and then re-record the new riff. This is a really good way to get out of your "comfort zone" without really changing anything. It works especially well for metal/heavy riffing and runs, but I've used this technique to turn an otherwise standard chord progression into something that I wouldn't have thought of otherwise. It's analogous to the "cut-up-technique" that lyricists sometimes use.