Herein we present a fast, reliable method for building nanoparticle-based 1D photonic crystals in which a periodicmodulation of the refractive index is built by alternating different types of nanoparticles and by controlling the levelof porosity of each layer. The versatility of the method is further confirmed by building up optically doped photoniccrystals in which the opening of transmission windows due to the creation of defect states in the gap is demonstrated.The potential of this new type of structure as a sensing material is illustrated by analyzing the specific color changesinduced by the infiltration of solvents of different refractive indexes.