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
- How do I delete all UNUSED images from my uploads directory?
- How to extend the gallery block in Gutenberg?
- Prevent WordPress from adding image’ title automatically
- Overide Gallery Default Link to Settings
- Creating a photo gallery in WordPress [closed]
- How can I alter the [gallery] markup?
- get_post_gallery with Gutenberg
- Custom wordpress gallery option
- Make a really simple gallery structure
- Best approach when modifying the Media Manager
- How to have different captions for same image, for galleries?
- get_post_gallery_images returns thumbs . I want full size
- Gallery Inside One Post
- How do i add class=”fancybox” to the default gallery?
- How to show description under an inserted image?
- WP 3.5 and Galleries – how to count images?
- Navigate with keyboard in Gallery shortcode
- Add existing images from Media Library in to custom gallery
- How to draw media details for Isotope gallery using Photoswipe
- Modifying the media-template.php file, the right way?
- Cropped featured image replaces original image in gallery
- First three images in post excerpt
- get images from post and make a zip
- how do i create a downloadable gallery with image descriptions?
- Bulk edit wordpress images alt and title attributes
- Change the output for [gallery] shortcode
- Set default link type to “file” for image galleries
- Add option to “Gallery Settings” section
- Making WordPress Gallery (.gallery-item) Responsive?
- 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
- Can I load posts via Ajax?
- 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…)
- WP_Editor – Remove TinyMCE Toolbars
- Having Problem On Getting WP Post Gallery Images URL
- How to add a “data-” attribute to the image tag of native gallery output
- Images Missing from built in WP Gallery
- Setting up a gallery with images and a zip download
- How to remove title attribute from gallery links and images
- How can I remove or change a border/outline on a picture when it is in a gallery page?
- 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?
- The WordPress Gallery, Grabbing The Link and Images?
- Add size in Gallery Settings in Media Library
- Post photo galleries [closed]
- Displaying a featured image (only img url) as the img src?
- Proper Way to Remove Thumbnail Links In Gallery
- Gallery images titles – get from post
- How to force WordPress to add new images at the beginning of the gallery?
- Disable Linked Gallery Images If Mobile Browser
- Possible to add same caption to all photos in a gallery?
- How to Add a Custom Colum on Thickbox Media Gallery Tab?
- WordPress 3.5 Gallery Menu Order not set?
- How to link Gutenberg Gallery images To Media file automatically?
- How to get post attachments in gallery post format template
- NextGen – Display Image Count Per Gallery
- Add a checkbox in Media Upload window
- have WP Gallery display the title instead of caption
- How to Make WordPress Default gallery responsive on mobile?
- Changing Gallery images size?
- Get a Page’s attachments in Gallery order
- How do I use two different images, one as a thumbnail and one as a linked image?
- remove featured image from gallery woocommerce [closed]
- How to get ID of images used in gallery?
- get attributes/part of the gallery shortcode
- Display all albums in nggallery on a page [closed]
- How can I show these pictures in two columns in my page?
- What is a good way to implement photo galleries on WordPress?
- Different captions for the same image in multiple galleries. Edit Image in Gallery locally
- Display latest 10 galleries
- How to determine if a post has attached images?
- How can I make wp default gallery responsive?
- How to get clean code for a gallery?
- Gallery set to “Media file”, showing as attachment page
- show other images from same gallery
- 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
- how do i embed the pdf gallery in wordpress post
- Attach custom gallery to a page
- Gallery Only Displaying One Thumbnail
- How To Put Multiple Image Galleries In A Single Post?
- Any way to “combine” galleries or show multiple galleries as one?
- How do I create a full-bleed background image on text mouseover? [closed]