Prussian blue analog (PBA) nanoparticles confined in the ordered mesoporosity of silica monoliths with twodimensional hexagonal structure are used as precursors and transformed into metal oxide or metal alloy by thermal treatment under oxidizing or reducing atmosphere. X-ray diffraction and transmission electron microscopy show that, after appropriate thermal treatment, the ordered silica monoliths contain spherical nanocrystals of mixed oxide and metal alloy aligned along the cylindrical pore axis. Their size (4 nm) is controlled by the diameter of the cylindrical pores of the silica monolith and their aggregation state by the structure of the porosity and the synthesis route. Furthermore, the chemical composition of the starting PBA precisely determines that of the oxide or alloy nanocrystals. The magnetic properties of the monoliths, governed by strong interparticle interactions, are very sensitive to chemical composition, size and aggregation state of the nanoparticles. The multi-scale control of the nanocomposite enables producing a light macroscopic permanent magnet, which is attracted to a NdBFe magnet at room temperature.