We investigate the effect of the dipole-dipole interaction (DDI) on the photon statistics with two atoms trapped in an optical cavity driven by a laser field and subjected to cooperative emission. By means of the quantum trajectory analysis and the second-order correlation functions, we show that the photon statistics of the cavity transmission can be flexibly modulated by the DDI while the incoming coherent laser selectively excites the atom-cavity system's nonlinear Jaynes-Cummings ladder of excited states. Finally, we find that the effect of the cooperatively atomic emission can also be revealed by the numerical simulations and can be explained with a simplified picture. The DDI induced nonlinearity gives rise to highly nonclassical photon emission from the cavity that is significant for quantum information processing and quantum communication.