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
- How do I delete all UNUSED images from my uploads directory?
- How to extend the gallery block in Gutenberg?
- how to get original image using wp_get_attachment_image_src
- How to have different captions for same image, for galleries?
- How to find attachment by it’s name?
- WP 3.5 and Galleries – how to count images?
- Cropped featured image replaces original image in gallery
- How do I delete all generated images from my server except those currently used in posts
- Theme Customiser Image Control
- Change the output for [gallery] shortcode
- Making WordPress Gallery (.gallery-item) Responsive?
- Get attachment ID of author_meta image – Attachment Metadata
- 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()
- How do i upload an image and return the image id?
- Setting up a gallery with images and a zip download
- The WordPress Gallery, Grabbing The Link and Images?
- Get an image from url in front end submission form
- How to upload image without post ID using the new media uploader?
- How do I delete thousands of unattached images?
- 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
- 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
- Link Featured Thumb to Attachment Page, If Possible
- Different captions for the same image in multiple galleries. Edit Image in Gallery locally
- Image still linked as attachment to page even though it has been deleted
- Why can I not view image attachment pages?
- Add image attachment to post via coding?
- Best option for photo/gallery handling?
- Add a new data attribute in tag
- Gallery post images on homepage?
- How to create a simple slideshow out of a post image gallery?
- Link to full size image or attachment page in photo theme
- add the post as canonical for attachment page wordpress
- How to change the target size of images clicked on in WordPress standard gallery
- Exclude featured image from gallery in wp-admin
- Add an attribute to attachments
- wordpress get gallery images title
- Pull images from the gallery
- Retrieve an array of image URLs that belong to a gallery
- Get attachments for posts that belongs to a specific category
- Rewrite all article pictures to link to file
- Custom Loop, Match Category with Page: How to display post featured image?
- Creating a post image to show in a gallery
- Don’t show images inserted into content
- Does wp_get_attachment_image_src also work with non-image files?
- wp get attachment image always gives me thumbnail
- Get title of post image is attached to
- Re-ordering images in existing post in wordpress 3.6.1
- Autosort uploads in galleries by filename
- How to display original unmodified thumbnail
- WordPress Attachments with old images
- What is the best way to associate multiple images to one page?
- How to get the cropped image from media library?
- Use full size images in a specific gallery
- How to automatically populate a gallery with images attached to posts of one category?
- Random Characters in the end of every image url in post
- Pagination between images (active/inactive)
- Random Image Script Working but Want to Avoid Duplicates
- changing the default picture size link url
- Attachments without images
- How to change an image source when rendering on frontend?
- Allow users to upload and display multiple photos
- Custom image size not displaying with wp_get_attachment_image()
- wp_insert_attachment() dupplicate attachment posts
- attachment_fields_to_save first parameter is null
- How to disable post-thumbnail from generation?
- How to Make Only Images Connected to a Post Show? Not Entire Media Collection?
- Troubles with code for upload a image
- Show WordPress Image Title Under Custom Portfolio Image
- Replacing an Image gallery
- Thumbnail gallery by date and taxonomy
- How to display every pictures from all the posts on one page?
- How to add multiple images in a page
- Extract url from next_image_link
- Lots of attachments is causing slow load
- how to display all images from their siblings/ from same parent?
- How to access & display images from a post without textual content ( and vice versa) according to best wordpress practices
- Adding different classes to different images depending on size for fine control of image layout in posts
- How can I use an image from an external source without uploading it to the media library
- Remove one srcset entry from wp_get_attachment_image
- 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
- Image shows up in editor, but not in published blog post
- How to add year and month path to old attachment images?