I noticed that this code is right. another admin changed the front page to anohter but I don't know why the fornt page instead of getting template from front-page.php it gets from page-gallery.php. that was interfearing and the pagination not works as expected.