We conducted research on the influence of periodic thermal loading on the shear behavior of sandstone through a series of direct shear tests with the aid of acoustic emission techniques. By capturing the evolution in pore structure with nuclear magnetic resonance technology and fractal theory to analyze the damage mechanism. The shear testing reveals that the periodic heating and air cooling sample exhibits a lower shear resistance compared to the continuous heating rock, with more pronounced differences observed in the water cooling samples. The peak shear strength and stiffness are greatly influenced by temperature and thermal loading methods, while the ultimate shear strength remains largely unaffected. Compared to samples with less severe damage, the acoustic emission macrocracking proportion of sandstone with more damage after thermal loading is more significant, corresponding to a smaller b-value. The study of the evolution in pore structure shows that mesopores and macropores exhibit favorable fractal characteristics distinct from micropores. The fractal dimension of mesopores and macropores are observed to be influenced by heating temperature and periodic thermal loading, as evidenced by their negative correlation with the thermal damage variable. After thermal loading, there was a negative correlation between porosity and fractal dimension in mesopores and macropores, indicating that the more severe the damage to the pore structure, the smaller the fractal dimension. The shear strength of periodic thermal loaded sandstone is closely related to the evolution of fractal dimension. The presence of thermal enhancement at 400 °C has been confirmed for the first time through fractal dimension analysis.