I think the Osgiliath battle lasted for many years? Not exactly trenches, but it was the only suitable river crossing in that area
I don't know if it's mentioned anywhere what happened in the meantime, but Denethor says he's expecting an enemy strike against Osgiliath shortly before the second attack happens, so it can't have been an active frontline at the time.