Dog thinks riding = playing
I'm fostering a dog who I'm considering keeping. He's fantastic except for one thing: when I'm riding, he thinks it's a way of playing. He respects the horses when I'm not on them (is even a little afraid of them in a good way), but when I'm in the saddle, he follows too close, barks at the horse, and jumps in the air trying to play. Unfortunately, my horse is very very dog tolerant and is not bothered by this, though it does affect my rides and it's not fun for me.
During the week days, barn time doubles as dog time. My dog tries to play with the foster dog when I'm riding, but the foster dog is only interested in following me on the horse. When I'm not riding, he's off playing with my dog and is not in the way. I ride at times when no one else is at the barn, so this is not currently affecting others, but it certainly could. I do not want to tie him since the resident barn dog gets aggressive with dogs who are leashed/tied when he is off leash (foster dog and resident dog get along fantastically when both off leash). He also barks a lot if he is tied and in your sights, but being ignored.
Is there a way to train a dog that this is unacceptable? I really like this dog and he's fantastic except for this one thing. But this one issue is large enough that it would be a deal breaker :(