Temptation is linked directly to what we think upon (Heb. 11:15). Temptation has to be entered into. We can avoid temptation by avoiding thoughts that generate temptation (Prov. 23:7). Since it is impossible to not think, we cannot just try to reject the negative thoughts in this world, but we must choose to think on the positive truths of God. This is where prayer comes in.
In prayer, we have our minds stayed upon God and therefore, are not receptive to thoughts that conceive temptation. Temptation or sin must be conceived (Jas. 1:14-15). In the physical realm, the easiest way to avoid an unwanted birth is to avoid conception, so it is in the spiritual world.
It is easier to avoid being tempted by being in constant communion with God, than it is to overcome temptation once it has been conceived.
Paul admonishes the Philippian believers to reflect and meditate upon eight positive principles of thinking that will lead to a victorious Christian life (Phil. 4:8). These are things that are 'true,' that is: honorable, truthful and upright. Things that are 'honest,' that is: honorable, truthful, genuine, not characterized by deception or fraud. Things that are 'just,' that is: in accordance with what is right, or right conduct; any circumstance, fact or deed that is right. Things that are 'pure,' free from defilement or impurity.
Things that are 'lovely,' pleasing, agreeable, inspiring love or affection. A 'good report,' that is: a saying or report that is positive and constructive rather than negative and destructive. 'Virtue,' which is moral excellence, righteousness and goodness. 'Praise,' or what is praiseworthy; expressing one's esteem of a person and his virtues. We need to focus on the good in every area of our lives. Recognizing God's hand in even the smallest things will bring peace and keep our hearts and minds following hard after the Lord.