Filter images and vimeolinks in a loop

Hi

Can someone help me with combining these to code snippets. They both work separately but I would like to be able to show the videos and images in the same loop and use anchor tags to navigate in the website…

Using images from one page in a loop

<?php $n = 0; foreach(page('heroes')->files()->sortBy('sort', 'asc') as $image) : $n++; ?>
<?php if($n == page('heroes')->files()->count()): ?>
<a href="#1" id="<?php echo $n ?>">
<?php else: ?>
<a href="#<?php echo $n +1 ?>" id="<?php echo $n ?>">
<?php endif ?>
  <div class="parent">
    <div class="child">
      <img src="<?php echo $image->url() ?>">
    </div>
  </div>
</a>

Grabbing vimeolinks

 <?php foreach(page('heroes')->vimeolinks()->yaml() as $vimeovid): ?>
 <div class="parent">
      <div class="child">
      <?php echo vimeo($vimeovid['vimeoid']) ?>
      </div>
  </div>
  <?php endforeach ?>

I guess easiest will be to show either the videos or the images first, don’t know how i will be able to mix them…

One way would be to loop through the files and then after the image div, call the nth() item of the vimeolinks (use toStructure() instead of yaml()) and check if the item exists. Or the other way round, start with the vimeolinks and grab an image….

Try this: (I might have forgotten some parenthesis or whatever, so please enable debugging to find my lovely errors)

<?php $n = 0; foreach(page('heroes')->files()->sortBy('sort', 'asc') as $image) : $n++; ?>
  <?php if($n == page('heroes')->files()->count()): ?>
    <a href="#1" id="<?php echo $n ?>">
  <?php else: ?>
    <a href="#<?php echo $n +1 ?>" id="<?php echo $n ?>">
  <?php endif ?>
    <div class="parent">
    <div class="child">
      <img src="<?php echo $image->url() ?>">
    </div>
  </div>
</a>
<?php 

$vimeolinks = page('heroes')->vimeolinks()->toStructure();
$count = $vimeolinks->count()-1;
if($n <= $count):
$vimeolink = $vimeolinks->nth($n);
?>
<div class="parent">
      <div class="child">
      <?php echo vimeo($vimeolink->videoid()) ?>
      </div>
  </div>
<?php endif ?>
<?php endforeach ?>

Ok. Thanks will try the toStructure()