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 get images by URL and save in uploads folder
- How to extend the gallery block in Gutenberg?
- Prevent WordPress from adding image’ title automatically
- Overide Gallery Default Link to Settings
- get_post_gallery with Gutenberg
- wp_get_attachment_image_src and server path
- get_post_gallery_images returns thumbs . I want full size
- get images from post and make a zip
- Insert an image into a post by API
- Function to call the attachment image from post
- Bulk edit wordpress images alt and title attributes
- How can I hide media library images from general users?
- 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]
- Separate attachment images from post loop
- How to display a shortcode caption somewhere other than the_content
- Displaying a featured image (only img url) as the img src?
- Allowing post attachments without allowing to insert in text
- Rename attachments during upload
- How to link Gutenberg Gallery images To Media file automatically?
- Pulling Post Image Attachments in WordPress 3.9
- get attributes/part of the gallery shortcode
- Different captions for the same image in multiple galleries. Edit Image in Gallery locally
- Display one random image, but only if landscape
- get_attachment_id() only get id of first attached image after post update
- Is there a way to get attachment data?
- How to change image url?
- get_children() not working properly – Only on one post?
- Custom page template to display all image attachments
- get the image of the post
- Get meta data from image
- Override img class in gallery
- Pull Random Attachments With Pagination
- Out of memory error reporting
- How can I attach hotlinked images in posts/pages within the same server?
- WordPress Image Attachment using remote image
- attachment.php code or tutorial
- Is this post using WordPress Gallery?
- Turn off image captions in gallery view?
- Unyson Framework doesn’t show gallery images
- Auto delete attachments that are older than x days
- Images attached to posts from library link to 404 error page
- Replacing the content of an image attachment using API
- Removing featured image from gallery?
- Gallery with thumbnail carousel
- Does wp_get_attachment_image_src also work with non-image files?
- wp get attachment image always gives me thumbnail
- Media gallery images url instead of ID on WP API Response
- Get all image IDs from the Media Library
- Get title of post image is attached to
- Get images attached to a specific page
- WordPress Creates Unused (Unregistered) Image Sizes
- Allow users to contribute images to a post
- What is the best way to associate multiple images to one page?
- Function to grab specific image IDs from media library.
- 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?
- How do I display the featured image from an image gallery using a reference in code? (example within)
- How to replace post image url before posting using api?
- How to get post id of first child of the same post type?
- Attachments without images
- attach several images to post + gallery
- how automatically show the image title before the image caption/description in a wordpress gallery?
- change the h3 subtitles of the wordpress gallery shortcode
- wp_insert_attachment() dupplicate attachment posts
- How to echo images Urls from a wordpress post, that are relally in the post
- SQL: How to find all attachments that are not used in any posts/pages/custom_post_types
- Allow users to upload attachments to certain posts
- get_post_gallery with Gutenberg
- How can I add an “Attach image to this post/page” link on the Add Media lightbox?
- Troubles with code for upload a image
- How do i replace the title attribute of img tag with the image caption
- Issue on Getting WP Gallery Items In cpt-single.php As Attachments
- Thumbnail gallery by date and taxonomy
- Create a custom attachment thumbnail for quick page load
- Extract url from next_image_link
- How can I hide previous_image_link() on first attachment page?
- Lots of attachments is causing slow load
- Retreive tags from attached post for media on page
- Thickbox not displaying just the image, instead showing full page in lightbox
- Multiple gallery thumnbnails on one page
- How do I set the sizes of my thumbnails when inserting a [gallery]?
- How to access & display images from a post without textual content ( and vice versa) according to best wordpress practices
- Display X images from a gallery in the sidebar
- Change attachment inside the_content using filters
- Automatically adding blog images to a portfolio/gallery
- How can we see which posts don’t have a featured image or it doesn’t exist anymore?
- How to get WordPress to resize images for srcset?
- Attachment tag archive