In previous installations of WordPress it was possible to number images in attachment.php using the code below, which was originally provided here. However, I'm finding that this code no longer works as the image numbers are inaccurate.
Is there a new code available?
<?php
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));
?>