check $blog is defined before looping through galleries