This should do it:
global $post;
$ancestors = get_post_ancestors($post->ID);
$photos = get_children(array(
'post_mime_type' => 'image',
'post_parent' => array_shift($ancestors),
));
$index = 0;
foreach($photos as $photo){
$index++;
if($photo->ID === $post->ID) break;
}
printf('%d out of %d', $index, count($photos));
Related Posts:
- Responsive Images
- Define size for `get_post_gallery_images`, they seem to have been resized to 150×150
- Media gallery – inserting full size images without link
- Getting the image title/alt attribute from the gallery shortcode
- Can I attach an image to a different post?
- Add data attribute to a gallery link?
- Add Download Button in prettyPhoto Plugin
- Display number of latest images from wordpress gallery in your homepage
- Why do the images only display in original size, not my custom size?
- Display Gallery Images from Custom Post Type
- Ipad app: Need uploaded images to go into “Gallery” as well as “Media Library”
- Gallery – custom html for inserting images
- Display custom gallery in each wordpress post
- Add anchor tag on previous_image_link / next_image_link
- Best approach when modifying the Media Manager
- How to show description under an inserted image?
- First three images in post excerpt
- How do you modify the HTML output of a Gallery item (using the gallery shortcode)?
- How I can get image description/title/alt for gallery image?
- How to include externally hosted images into a gallery block
- How can I make all gallery images to open in a new window?
- How do I get gallery thumbnail URL and change the default thumbnail size?
- NextGen – Display Image Count Per Gallery
- have WP Gallery display the title instead of caption
- Changing Gallery images size?
- What is a good way to implement photo galleries on WordPress?
- Display latest 10 galleries
- 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?
- WordPress grab first image from gallery
- How to add a random image to a post from gallery and only show one?
- How can I create a gallery showing Ken Burns effect, when mouse hovers over images? [closed]
- Get attachments but only from post gallery?
- WooCommerce-like featured gallery
- WordPress show Gallery Title and Captions
- Extracting gallery images in WordPress 3.5 on index.php
- How to use photo in multiple posts?
- attachment.php code or tutorial
- Upload photos to WordPress via ftp w/ [gallery] shortcode?
- NextGen Gallery Slideshow Positioning Issue
- Install Gallery 3 in Subdirectory of WordPress
- Inside text editor my preview gallery images are in full size
- How can I display an image description, from an image gallery?
- How do I export WordPress galleries?
- Ways to show multiple, separate galleries per post?
- Gallery Shortcode Showing IDs
- How to get the Gallery form/section just like in Gutenberg block?
- How to show a manageable list of images on a post?
- Get all image IDs from the Media Library
- Allow users to contribute images to a post
- Timthumb.php image gallery not working on Multisite WordPress
- Change default gallery images – Currently they are displaying full size imagese
- How to get images using taxonomy ( WP Media Folder)
- How to change gallery grid from 4 columns to 3 columns? [closed]
- Category view with contents of [gallery]s shown
- Gallery order specified by shortcodes is ignored in gallery function
- How to display some of images from media library?
- How to add a div around the default gallery output
- limit number of images shown from gallery
- What is the plugin to import image from URL?
- Excluding post thumbnail from the attachment.php when using wordpress gallery
- photo gallery implementation like tmz
- How do I display the featured image from an image gallery using a reference in code? (example within)
- Get the a specific image from the post gallery linked to post_id
- How to enlarge thumbnail on mouseover?
- How do I test whether [gallery] is empty?
- attach several images to post + gallery
- Personalized Gallery what are my options?
- get_post_gallery with Gutenberg
- Implementing a modal(lightbox) for all images in all post-gallery posts
- Images hidden from wordpress gallery
- Easy Image Gallery – Retrieve Serialized Data
- Output all images from gallery inside a slider
- How to have two galleries side by side?
- Integrate video and iframe in a post type gallery
- WordPress Gallery is not displaying
- Error while uploading photos
- How do I extract a gallery image from databse?
- Issue on Getting WP Gallery Items In cpt-single.php As Attachments
- Options for an SEO gallery?
- attachment.php & flexslider—linking thumbnail to specific image
- gallery image size
- Moved blog – galleries don’t work
- I want to add a gallery to a post but I don’t want it displayed in the content?
- Breadcrumbs for Single Image page
- Gallery requires a featured image but does not show it in posts/pages
- Slider do not add alt attribute. Cant get alt attribute from a media library!
- wp_get_attachment_link() add rel attribute if the link points to direct image
- Paginate Gallery [closed]
- Hide the ‘Gallery Settings’ section of the Gallery tab of the media Thickbox
- Gallery image must open up in fancybox directly not post page
- Adding a “More Galleries” Page to the End of an Image.php Gallery
- *box for images displayed as a post’s [gallery] [duplicate]
- Getting top Image From the Gallery and printing out a thumbnail with Exact Dimensions
- Multiple Gallery Posts With Sldiers
- Cany anyone name this lightbox? [closed]
- Convert WordPress default grid to carousel
- Images uploaded in customized gallery do not link to media
- Trouble with WordPress Gallery since update using has_block(‘gallery’