Counting each file


I’m wondering if there is away to pull a specific file number from the count function.
eg. there is a total of 5 files and using a for each function i would love to have the result of:

1 of 5
2 of 5
3 of 5
4 of 5
5 of 5

<?php echo $page->files()->current-count?() ?> of <?php echo $page->files()->count() ?>

Thankful for advice!

If I get you right, your are looking for the ‘nth()’ method:

Hi @texnixe thank you for the reply.

I’m trying out the nth() as you suggested it’s not giving me the result i was hoping for.

I want to return number 1 for the first image and number 2 for the second image somehow

I’m trying to caption a series of images so each images have the total number of images next to the current image number


Ok, then just use a counter variable in your loop:


$count =1;

foreach($page->images() as $image) {
// whatever goes here ...
echo "this is image no " . $count . " of " . $page->files()->count();

SOLVED! Thank you @texnixe