With the availability of the huge amounts of data produced by current and future large multiband photometric surveys, photometric redshifts have become a crucial tool for extragalactic astronomy and cosmology. In this paper we present a novel method, called Weak Gated Experts (WGE), which allows us to derive photometric redshifts through a combination of data mining techniques. The WGE, like many other machine learning techniques, is based on the exploitation of a spectroscopic knowledge base composed by sources for which a spectroscopic value of the redshift is available. This method achieves a variance σ2(Δz) = 2.3 × 10−4 [σ2(Δz) = 0.08, where Δz=zphot−zspec] for the reconstruction of the photometric redshifts for the optical galaxies from the Sloan Digital Sky Survey (SDSS) and for the optical quasars, respectively, while the root mean square (rms) of the Δz variable distributions for the two experiments is, respectively, equal to 0.021 and 0.35. The WGE provides also a mechanism for the estimation of the accuracy of each photometric redshift. We also present and discuss the catalogues obtained for the optical SDSS galaxies, for the optical candidate quasars extracted from the Data Release 7 of SDSS photometric data set (the sample of SDSS sources on which the accuracy of the reconstruction has been assessed is composed of bright sources, for a subset of which spectroscopic redshifts have been measured) and for optical SDSS candidate quasars observed by GALEX in the ultraviolet range. The WGE method exploits the new technological paradigm provided by the virtual observatory and the emerging field of astroinformatics.