Cantor families of periodic solutions for wave equations via a variational principle