First thing we do is wrap everything in a function called setFacebookLike(). This is important so that you can attach it to the callback of an AJAX pagination request, thus ensuring that your Like buttons survive any type of DOM tinkering.
Inside the function, attach some Facebook attributes to the HTML tag. Next, remove and/or empty out the contents of the Facebook Like divs that have been left over, if there are any. Finally we're in a position to loop through the anchors.
With this syntax, the “this” in the function is the anchor we're making a button for, so all its attributes are readily available to us. (I've broken up initializing the URL variable to ensure it works with staging servers, which often have different URL roots and databases, and in this case, different articles to like.)
Once we store the like button markup into a variable like this…
…we can shove into the DOM anywhere, using our $(this) anchor as a starting point:
Now, you call setFacebookLike().