The temperature of photon and its energy Do photons have temperature? If not, does it mean that photon lose energy while travelling through space?  As the planets farther away from the sun are comparatively cooler than the one that are closer to it, does it imply that photon also lose energy?
 A: We must be careful with such a question, because both the notion of photon and that of temperature are not straightforward.
Photon:
Lamb (1995, of the Lamb shift) wrote:

the author does not like the use of the word "photon", which dates from 1926. In his view, there is no such thing as a photon. Only a comedy of errors and historical accidents led to its popularity among physicists and optical
scientists.

One reason is explained by Wald (1994) among others:

standard treatments of quantum field theory in flat spacetime rely heavily
on Poincaré symmetry (usually entering the analysis implicitly via plane-wave expansions) and interpret the theory primarily in terms of a notion
of "particles". Neither Poincaré (or other) symmetry nor a useful notion of
"particles" exists in a general, curved spacetime, so a number of the familiar
tools and concepts of field theory must be "unlearned" in order to have a
clear grasp of quantum field theory in curved spacetime. [p. ix] [...] the
notion of "particles" plays no fundamental role either in the formulation or
interpretation of the theory. [p. 2]

Basically, two observers in two different reference frames generally won't even agree on the number of photons, let alone their "identities". See also Davies (1984).
A photon is a quantum of energy of a mode of the electromagnetic field, see for example van Enk (2003) for a very concise overview. This means not only that photons don't have temperature, but also that they don't have or lose or gain energy, nor do they really "travel".
Rather, we can speak of the energy and of the temperature (but see below) of a mode of the electromagnetic field. The photons are, roughly speaking, a count of the quantized energy of that mode. The best place to understand the relation between field modes, their energy, and photons are Glauber's (1965) lectures, in my opinion.
Temperature:
The term "temperature" denotes many different notions and quantities, somehow related to one another. These relations are understood in some cases, but – still today – not in other cases. There's a recent stimulating book by Biró, Is There a Temperature?: Conceptual Challenges at High Energy, Acceleration and Complexity (2011) which explores this complex network of relations.
There's the (macroscopic) thermodynamic temperature, for example. And there are statistical temperatures, of at least two kinds: one related to uncertainty and stochastic variability, the other to a space-time average. For the relation between the two see for example Kirkwood (1946) and Murdoch & Bedeaux (1996). The relations among these temperatures are clear for an ideal gas, for example, but still not so clear for more complex systems; in fact, the relations may even be non-unique (Jepps, Ayton, Evans 2000).
As far as I know, from a macroscopic perspective the electromagnetic field doesn't have a thermodynamic temperature. Only material bodies do – as is clear for example from the term "black-body temperature", which is associated with "black-body radiation". This association gives us a link between electromagnetic field and thermodynamic temperature, but I personally don't ascribe that temperature to the electromagnetic field. See Hutter & van de Ven (2006) for an overview of the macroscopic description.
From a microscopic and statistical point of view we can associate a statistical temperature with (a mode of) the electromagnetic field: such temperature is the coefficient summarizing or parametrizing our uncertainty about the field's energy – and so, from a quantum-theoretic point of view, our uncertainty about the number of photons in the (mode of) the field. Our uncertainty is given by usual Boltzmann-like formulae, classical or quantum. Related to this uncertainty is also our mean guess of the energy. This is the relation implicitly understood when we speak of the temperature of th microwave background, for example.

To summarize in very rough terms, the number of photons tells you the amount of energy of an electromagnetic-field (mode), obtained under a specific experimental procedure (this last precisation is necessary in quantum theory). The temperature tells you something about your uncertainty about the result of such measurement, or equivalently how much variability you will observe in the registered number of photons as you repeat such measurement in identical experimental conditions.
References

*

*Biró: (2011) Is There a Temperature?: Conceptual Challenges at High Energy, Acceleration and Complexity (Springer).


*Davies (1984): Particles do not exist. In Christensen (ed.): Quantum Theory of Gravity (Hilger), 66.


*Glauber (1965): Optical coherence and photon statistics. In DeWitt-Morette, Blandin, Cohen-Tannoudji (eds): Quantum Optics and Electronics (Gordon & Breach), 63.


*Hutter, van de Ven (2006): Electromagnetic Field Matter Interactions in Thermoelastic Solids and Viscous Fluids (Springer).


*Jepps, Ayton, Evans (2000): Microscopic expressions for the thermodynamic temperature. Phys. Rev. E 62, 4757.


*Kirkwood (1946): The statistical mechanical theory of transport processes: I. General theory. J. Chem. Phys. 14, 180.


*Lamb, Jr (1995): Anti-photon. Appl. Phys. B 60, 77.


*Murdoch, Bedeaux (1996): A microscopic perspective on the physical foundations of continuum mechanics – Part I: Macroscopic states, reproducibility, and macroscopic statistics, at prescribed scales of length and time. Int. J. Engng Sci. 34, 1111.


*van Enk (2003): Entanglement of electromagnetic fields. Phys. Rev. A 67, 022303.


*Wald (1994): Quantum Field Theory in Curved Spacetime and Black Hole Thermodynamics (University of Chicago Press).
A: The photons themselves do not have temperature as such. However, photons do contribute to the temperature of objects since they carry energy. A very good example is the microwave background radiation which is known to contribute a temperature to the universe at about 3K. One can work out the frequency of these photons using the basic relation $k_BT_{mwb}=hf$ where $k_B=1.381\times 10^{-23}$JK$^{-1}$ and $h=6.63\times 10^{-34}$Js, so that the requency turns out to be in the microwave part of the electromagnetic spectrum. Photons contribute to the temperature of your body when you sit in the sunshine and absorb the sunlight.
The farther you go from the sun the cooler, correct, but this is because the intensity of solar light is inversely proportional to the square of the distance from the sun. On Earth we receive about 1350 W/m$^2$ of solar power. But on Mars, which is about 1.52 the Earth-Sun distance, it is only about 584 W/m$^2$. 
A: This is really just an extension to JKL's answer since I wanted to pick up on his point about the microwave background, but first it's worth mentioning that although individual photons do not have a temperature, EM radiation can be assigned a temperature. The EM radiation emitted by an object has a spectrum that depends on its temperature through Planck's law. So if you measure the spectrum of radiation it is sometimes possible to assign it a temperature through Planck's law, and indeed this is how the cosmic microwave background is assigned the temperature of 2.7 kelvins.
But back to the CMB: I would guess your question is asking if an individual photon can lose energy by radiating away like a cooling object, and the answer is no. However light can cool if the spacetime through which it is travelling is expanding. The light cools because its energy is spread out over a larger volume of space. This is how the cosmic microwave background has cooled from its original very high temperature of about 3,000K to its current value of 2.7K.
A: At thermal equilibrium temperature $T$ is defined by $$\frac{1}{T}=\frac{\partial S}{\partial U} $$ Where $S$ is the entropy and $U$ is the total energy. Since a system composed of photons has a well-defined energy and entropy,  photons can be said to have a particular temperature if the whole ensemble could be in thermal equilibrium with some hypothetical environment.
Planets further from the sun are cooler than close ones because the same photon flux is spread out over a greater area compared to the size of the planet: Earth's cross sectional area is a greater fraction of the surface area of a sphere the size of it's orbit than Neptune's for it's orbit. This means fewer photons per unit area hit Neptune than Earth. Photons do lose some energy going out that far (redshift from the sun's gravity, this is from general relativity), but this effect is tiny.
A: Assume the sun emits a certain number of photons, such that, at 1m from the sun's surface 1 million photons go through each square meter. As the photons spread radially out from the sun, their number stays the same, but they have to cover larger and larger areas. At 10m from the sun, those $10^6$ photons will cover an area of $10$ x $10 = 100m^2$. So the density of the photons will be 100 times smaller than at 1 m. This shows how, as you travel away from the sun, the density of photons decreases inversely proportional to the square of the distance from the sun.
That is what causes the temperatures of the planets to reduce with their distance from the sun.
A: Well it is not the total energy alone which determines temperature but the "quality" of energy as well. Temperature is a measure of average kinetic energy or also related to the wavelength of the photon. If you have enormous quantity of microwave range of photons the temperature anywhere may not rise above 3K. Classically and close to reality it is Weins displacement law that determines temperature in a spectrum.  
A: I'm reading other responses, and I'd like to try to arrive my understanding, and hear where I'm wrong.
First of all, something that's pretty hard to find is whether the cosmic background radiation basically consists of photons. I know it's "electromagnetic radiation". But that's just, like, photons, right? At some frequency that we don't have the right eyes to see, in other words, just some particular color of light?
It sounds like individual photons have energy which can be transferred upon striking an atom (e.g., how a red hot space heater/radiator will make atoms in its line of sight hear up), but that this is NOT what physicists are referring to when they say a particular set of photos "have temperature".
What do they mean? Well, if a photon is emitted in the form of radiant heat by an object, then the frequency of the photon gives you information that you can use to work out the implied temperature of the source object.
It has also been theorized, and I assume confirmed, that photons that travel across expanding spacetime will lose frequency, which is the same as losing implied temperature of their source.
So now we observe that there is this ambient, directionless flow of photons all around us, and something about the relative frequency of the photons we observe in various directions makes us think that they are from the same original source, just shifted in frequency different amounts, and we think the reason is that they have traveled through regions of space where spacetime was expanding at different relative velocities. And our best guess as to the implied source temperature, for ALL these photons, adjusting for all of the various expansion, is a crazy hot temperature; and our best guess for the location is that all of the photons came from the same exact point in space.
A: According to the laws of physics the electromagnetic particles called photons individually have a zero thermodynamic temperature. This astonishing discovery means that they are the coldest quantum particles in existence
