Dogs are pack animals, and respond to a hierarchy system.
As a puppy, a dog will bond with anyone who gives him warmth and attention.
As he matures, he will realise the way the 'pack' is formed, and he will make sure he falls in line - this is usually by bonding with one - sometimes two - adults whom the dog senses are 'in charge'. It doesn't matter how the household is organised in human terms, the dog will decide in his own sense of things whom the 'top dog' is, and will ally himself accordingly.
It is the sense of pack identity that causes dogs to attack children ithout warning. The dog can feel that a child is pushing for a posityion that the dog feels is his, and he can, and will, fight for it. That is instinct, and natural to the dog's way of things - which is why these atacks come without warning or apparent provication.
Loyalty is earned and maintained by allowing your dog his own space within the group, and to be reminded of his own place when needed.