1 and 2 John go together well. 1 John serves as an extended discussion of what is only briefly discussed in 2 John. 1 John was written to the early church to warn them about a group of people who rejected Jesus as the Messiah and did not believe in loving their neighbor. 2 John accomplishes this same goal in only one chapter. 3 John, however, appears to not be about these two principles at all, but things may not be as they appear.
In 3 John, the author comments on the character of 3 individuals: (1) Gaius, the one to whom the letter was addressed, (2) Diotrephes, and (3) Demetrius. Gaius was a shining light in a troubled congregation, but he could use some extra encouragement. Should he follow Diotrephes, who was an obvious leader and powerhouse among the believers? Or should he follow the example of Demetrius, who was perhaps cast out of the church by Diotrephes and may have even appeared weak to some of the latter's followers?
In answering this question, we discover that this third epistle is related to the previous two in that it serves as a living example of the principles already discussed.
For example, in 2 John, John talks about the dangers of receiving someone into your house, a way of supporting them in their ministry, that denies that Jesus is the Messiah. This warning is similar to the many reminders in the Hebrew Scriptures to do such and such command because “I am the LORD.” The Israelites were to have no other God's before the LORD because the other gods allowed child sacrifice, oppression, and all sorts of evil whereas the LORD is the God of the oppressed. Similarly, to reject Jesus as the Messiah is to reject His nonviolent, heavenly kingdom. In the first century when there were extreme tensions between the nations, believing in Jesus meant rejecting the notion of peace through violence. The first Christians weren't to support pseudo-apostles and others who carried this message of hatred and violence, which was the antichrist.
Alternatively, if someone did come proclaiming Jesus as the Messiah, then accepting them into your house was a way of participating in their ministry. Gaius had done just that.
Beloved, you are acting faithfully in whatever you accomplish for the brethren, and especially when they are strangers; and they have testified to your love before the church. You will do well to send them on their way in a manner worthy of God.3 John 5–6
Therefore we ought to support such men, so that we may be fellow workers with the truth.3 John 8
It was in this way that he was “walking in truth.” Walking in truth in 2 John was not about having all of one's doctrine correct; it was about showing love towards one's brothers and sisters in Christ. Diotrephes, on the other hand, went out of his way to reject anyone sent by the apostles, and he kicked anyone out of church who dared accept them.
For this reason, if I come, I will call attention to his deeds which he does, unjustly accusing us with wicked words; and not satisfied with this, he himself does not receive the brethren, either, and he forbids those who desire to do so and puts them out of the church.3 John 10
Diotrephes was doing the very thing 1 and 2 John warned about. So, John told Gaius to find someone to follow who set a good example.
Beloved, do not imitate what is evil, but what is good. The one who does good is of God; the one who does evil has not seen God. Demetrius has received a good testimony from everyone, and from the truth itself; and we add our testimony, and you know that our testimony is true.3 John 11–12
3 John fits well with 1 and 2 John in that it exemplifies the type of person that God wants, and doesn't want, us to be.