2 Answers
2

Instead of using 2 separate functions to grab the attachment you can use the same function, and then add the URL in separately using wp_get_attachment_url, making the logic much clearer, and reducing the amount of work needed:

Now, the just mentioned two methods allow you to use the link="none" parameter when you don't want the thumbnails in a specific gallery to be hyperlinked. (EDIT: Take a look at Tom's answer, he's provided some better code.)