Image Gallery Numbers for 3.5

There is no complete solution possible. And that is not new.

Any image can be a part of a gallery in a post that is not that image’s parent. So the post parent is not a useful parameter. The new interface makes such galleries easier to create, but they were possible in earlier versions too.

Even if the attachment’s parent contains a gallery with that image – there could be another gallery with the same image. Yes, you can create multiple galleries and re-use images.

What you can do:

  1. Find all posts with galleries.
  2. Find all galleries using that image.
  3. Parse those galleries to detect the order (good luck with random!).
  4. Try to detect from which post the user came to see the current image (sessions?). Maybe she found it per Google.

Alternative:

Create an endpoint for post galleries to keep the relation intact. With an URL like …

example.com/blog/postname/gallery/1/4/

… you would know you are on the fourth attachment for the first gallery that belongs to the post with the slug postname.