EDIT: It works, I was just completely stupid, and not realizing that the texture coordinates has been already set up in:
layer2.append(sf::Vertex(sf::Vector2f((x2 + 0) * size, (y2 + 0) * size), sf::Vector2f((tx2 + 0) * size, (ty2 + 0) * size)));
So basically the first sf::Vector2f defines the position of the vertex, and the second defines the texture coordinates.
And what it does now is to create an empty vertex array at startup, and append a quad if the tile ID is larger than zero, if I understand correctly. And what got me confused was that I used to believe that all the vertices in the array needs to be connected, not realizing that just because they are in the same array, they can be positioned individually (similar to the way like the polygons are stored in a 3D mesh file, they can be scattered around without being connected, while still belonging to the same model (array)).