Do the upper parts in all cadences move in contrary motion to the bass.if I write it like that, am I wrong? Or is it only for adjacent chords?
Making the upper parts move in contrary motion to the bass is a good "rule of thumb" to avoid writing consecutive 5ths and octaves, but it is not necessary in a cadence, or anywhere else.
In 'harmony exercise' land, contrary motion is good and can help in avoiding parallels. But other approaches can be more exciting!
Once you get beyond imitating hymn tunes, you'll find parallel motion, unisons etc. used a great deal. Sometimes music demands smooth, full harmony. Sometimes a concerted, exultant leap upwards is more appropriate.
(But in harmony exercises, obey the rules.)
You can have parallel movements, it is just more likely for consecutive octaves/fifths when you do it. So for newbies it is just easier to teach it like this.
You can, for instance, have your cadential 6/4 chord progressions where two voices stay on the same pitch and the other two move a step down in parallel.
Good voice leading is the main issue in these harmony questions, the form of your outer voices, while not unimportant cannot be good at the voice leading's expense.