I am actually teaching my boy to do this right now. It works best from the grown to begin with. I began with a long training whip and stood beside him at his shoulder.
Begin by teaching him to move his shoulder and rear separately. I would stand next to him and tap tap tap tap the whip on his shoulder until he became annoyed and moved his shoulder away from me. Because I was holding him from going either forwards or back, he crossed one leg over the other and moved sideways from me.
Immediately stop the tapping and reward him. For the first little while, reward even the slightest sideways movement. When he finally gets it, ask for more steps until you can get him to pivot.
Repeat the process with his back end (back end was significantly easier for my boy than learning to move his shoulder. Probably because I do it every day in his pen when I want him to move his bum out of my way
Once these are down, put them together. Alternate tapping on the shoulder and bum so that he moves one and then the other. Reward for ANY sort of effort.
With my boy, I figured out that tapping his belly right before it meets his back leg worked easier for getting him to move both ends sideways rather than the alternation thing which made it very easy to teach from the saddle.
Once he understand the ground cues, get on him and give him the leg/heel cue that you intend to use to ask him to sidepass. Give him a second to ponder what it is you are asking him to do...and then use your ground aid (training whip) from the saddle. Reward any movement in the right direction
He may still need the aid for a little while, but he should get this fairly quickly and begin responding to the leg command on his own.
After that you can practice nose to fence or the other way around if he likes to try to back up.
Hope this helps!
Edit: while you're on the ground, work on flexing his neck as well. It'll help out later if you want to teach him leg yeild and halfpass