1

Is there a way, in an image gallery, to display what number the image is in the gallery in the image.php template? I'd like to incorporate this into my next / previous button area.

For example, if I'm on the first image out of twenty it would say "1 of 20".

1 Answer 1

1
+50

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));
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.