Jesus did not have any strong objection to mixing his metaphors: so this passage falls into two halves both using shepherd imagery but in rather different ways. No problem. It means you get two short sermons instead of one long one!
It was a stock image in Old Testament days to liken the king -- both in Israel and in other countries -- to a shepherd. King David, the youngest son of Jesse taken from the flock to be anointed king, was the prototype.
On the death of Moses, Joshua is appointed as the new leader in these words:
Let the Lord, the God of the spirits of all flesh, appoint someone over the congregation who shall go out before them and come in before them, who shall lead them out and bring them in, so that the congregation of the Lord may not be like sheep without a shepherd. (Numbers 27:16-17)
The prophets knew the image:
He will feed his flock like a shepherd; he will gather the lambs in his arms, and carry them in his bosom, and gently lead the mother sheep. (Isaiah 40:11)
But the prophets could take up and reverse the image and speak of leaders as faithless shepherds:
Oh, my worthless shepherd, who deserts the flock! (Zechariah 11:17)
In the first century shepherds had joined sailors, camel drivers, butchers and others as members of a despised occupational group. This is why Luke has shepherds visit the infant Jesus: he is kick-starting a theme of his of how Jesus goes preferentially to the outcasts and those on the margins of society.
To our urbanised eyes, one sheep looks much any other, especially when a flock of them is being coaxed around by a sheepdog. Any individuality they may have is merged into the collective identity.
Palestinian sheep and their shepherd were different. We have many useful terms for those things which interest us and most touch our welfare. The exact nature of snow conditions is a matter of life and death to an Inuit and it is said that they have many names for the varieties of snow. This variant will build a life-saving igloo, this other will not. Likewise the Bedouin of the desert has a very wide vocabulary for the different types of sand which influence his safety.
The Palestinian shepherd had a like width of language for every age, condition and characteristic of a sheep. Even more he had individual names for each and every sheep. He went ahead of them in search of the probably sparse pasture in an arid landscape and summoned them by name to follow him. (A sheep therefore will not follow a stranger -- that is, someone who does not know the sheep's name.) So the shepherd's care for this sheep and that sheep and every sheep is personalised and particular. A fine model therefore for the particularised love of Jesus for his disciples. We are each of us 'the disciple whom Jesus loved'.
The divine providence towards human beings is equally personal. God is wholly simple and his attention cannot be divided between two of us. We each have his whole attention and love simultaneously and perpetually.
The shepherd image was so much part of the culture that it is surprising that the audience does not understand.
So therefore, another use of the image: Jesus is the gate of the sheepfold -- that is, the only person who can admit someone to the sheepfold of the Evangelist's congregation. Perhaps there is a polemic here against the Pharisees or even against some deviant would-be leader within the Evangelist's group. Another task of actual shepherds would be defence of the sheep against the predators of the desert, lions and the like.
But what of the other side of the shepherd imagery? Actual shepherds belonged to a despised and dishonourable occupation. Jesus is the shepherd of this people and inherits the full glory of the imagery as it had been applied to David and others. But the Jesus who reigns from the Cross in John's gospel is also the one of whom it is said
But I am a worm, and not human; scorned by others, and despised by the people. All who see me mock at me; they make mouths at me, they shake their heads (Psalm 22:6-7)