The answer was to assign a count to each attachment:
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'order_by' => 'menu_order',
'order' => 'DESC'
);
$attachments = get_posts( $args );
if ( $attachments ) {
$count = 0;
foreach ($attachments as $attachment) {
$link = get_permalink($attachment->ID);
$link = add_query_arg('img',$count,$link);
echo '<div class="thumbnail">';
echo '<a href="'.$link.'" >';
echo wp_get_attachment_image( $attachment->ID, 'small' );
echo '</a>';
echo '</div>';
$count++;
}
}
And then link up with that on attachment page using the assigned number.
Related Posts:
- Exclude images from “inserted into post” when trying to get attachments
- How to remove title attribute from gallery links and images
- Customizing the attachement page to show rest of all images in a gallery from post
- Retrieve Image Attachments Getting Post Thumbnail Image First
- One picture belonging different galleries?
- Excluding post thumbnail from the attachment.php when using wordpress gallery
- Can i have 2 separate Galleries on 2 separate pages each go to a DIFFERENT Attachment.php file?
- wp_get_attachment_link() add rel attribute if the link points to direct image
- Image Attachments Query Not Working If Post Is Loaded Via Ajax
- Programmatically adding images to media library
- How do I delete all UNUSED images from my uploads directory?
- Programmatically get images by URL and save in uploads folder
- How to extend the gallery block in Gutenberg?
- how to get original image using wp_get_attachment_image_src
- Can I attach image to post without adding it to post?
- Prevent WordPress from adding image’ title automatically
- Overide Gallery Default Link to Settings
- Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords
- get_post_gallery with Gutenberg
- How to have different captions for same image, for galleries?
- wp_get_attachment_image_src and server path
- get_post_gallery_images returns thumbs . I want full size
- How to find attachment by it’s name?
- WP 3.5 and Galleries – how to count images?
- Navigate with keyboard in Gallery shortcode
- Cropped featured image replaces original image in gallery
- List most recent image uploads, but only for specific custom post type
- How do I delete all generated images from my server except those currently used in posts
- get images from post and make a zip
- Insert an image into a post by API
- Function to call the attachment image from post
- Theme Customiser Image Control
- Bulk edit wordpress images alt and title attributes
- Change the output for [gallery] shortcode
- How can I hide media library images from general users?
- Making WordPress Gallery (.gallery-item) Responsive?
- How do you modify the HTML output of a Gallery item (using the gallery shortcode)?
- Get attachment ID of author_meta image – Attachment Metadata
- How to include externally hosted images into a gallery block
- Associate an existing image with a post
- Programatically creating image attachments from local URLs and setting featured image
- Excludes posts that don’t have attachments in the_content()
- Use Media Library to manage galleries like Nextgen (with folders, albums, collections, tags, categories, terms…)
- How do i upload an image and return the image id?
- Get Attachment ID from URL [duplicate]
- Setting up a gallery with images and a zip download
- Separate attachment images from post loop
- How can I make all gallery images to open in a new window?
- How to display a shortcode caption somewhere other than the_content
- copy attachment title to description and alt text
- The WordPress Gallery, Grabbing The Link and Images?
- Get an image from url in front end submission form
- Open the attachment details modal
- Displaying a featured image (only img url) as the img src?
- How to upload image without post ID using the new media uploader?
- How do I delete thousands of unattached images?
- Allowing post attachments without allowing to insert in text
- How to force WordPress to add new images at the beginning of the gallery?
- Applying class to links around self hosted images embedded to posts/pages
- Rename attachments during upload
- How to link Gutenberg Gallery images To Media file automatically?
- Regex to turn embedded images in to attachments
- Re-process Images
- Show prev and next post links for parent post of current image in attachment page?
- How to Make WordPress Default gallery responsive on mobile?
- Get a Page’s attachments in Gallery order
- Pulling Post Image Attachments in WordPress 3.9
- get attributes/part of the gallery shortcode
- Link Featured Thumb to Attachment Page, If Possible
- Different captions for the same image in multiple galleries. Edit Image in Gallery locally
- Regenerate missing _wp_attachment_metadata
- Make alt text required when setting a featured image
- Image still linked as attachment to page even though it has been deleted
- Editing built in Gallery shortcode to filter by categories
- Gallery images stored elsewhere (preferably Google Drive)
- WordPress gallery previous/next buttons showing all media library images
- Any way to “combine” galleries or show multiple galleries as one?
- Display one random image, but only if landscape
- get_attachment_id() only get id of first attached image after post update
- Why can I not view image attachment pages?
- Add image attachment to post via coding?
- Is there a way to get attachment data?
- How to change image url?
- Best option for photo/gallery handling?
- Add a new data attribute in tag
- get_children() not working properly – Only on one post?
- Gallery post images on homepage?
- Custom page template to display all image attachments
- How can I use an image from an external source without uploading it to the media library
- How to get WordPress to resize images for srcset?
- Remove one srcset entry from wp_get_attachment_image
- Attachment tag archive
- Images uploaded in customized gallery do not link to media
- Get field added via attachment_fields_to_edit filter in Gutenberg
- Fix position of an image while using elementor pro gallary widget
- Define how an attached image is rendered
- Image shows up in editor, but not in published blog post
- How to add year and month path to old attachment images?
- How can I get or the intermediate size of an image with wp_get_attachment_image_src without using post meta?
- wp_get_attachment_image with custom size not rendering possible 2x srcset image