Jump to content

Grab several certain images from array


clickpass
 Share

Recommended Posts

I want to split my output of an image array, see my code here:

<div class="row">
  	<?php foreach($page->umf_imgs as $image) {echo "<div class='one-fourth column refs'><img src='$image->url'></div>";} ?>
</div>
<div class="row">
  	<?php foreach($page->umf_imgs as $image) {echo "<div class='one-fourth column refs'><img src='$image->url'></div>";} ?>
</div>
<div class="row">
  	<?php foreach($page->umf_imgs as $image) {echo "<div class='one-fourth column refs'><img src='$image->url'></div>";} ?>
</div>

The number of images is 11, but I only want to add four in a row. Is it possible to grab them, e.g. image 1-4, image 5-8, image 9-12?

Link to comment
Share on other sites

I want to split my output of an image array, see my code here:

<div class="row">
  	<?php foreach($page->umf_imgs as $image) {echo "<div class='one-fourth column refs'><img src='$image->url'></div>";} ?>
</div>
<div class="row">
  	<?php foreach($page->umf_imgs as $image) {echo "<div class='one-fourth column refs'><img src='$image->url'></div>";} ?>
</div>
<div class="row">
  	<?php foreach($page->umf_imgs as $image) {echo "<div class='one-fourth column refs'><img src='$image->url'></div>";} ?>
</div>

The number of images is 11, but I only want to add four in a row. Is it possible to grab them, e.g. image 1-4, image 5-8, image 9-12?

Link to comment
Share on other sites

<div class="row">
<?php
$i = 0;
foreach ($page->umf_img as $image) {   
  echo "<div class='one-fourth column refs'><img src='$image->url'></div>";
  if ($i % 4 === 0) {
  echo '</div><div class="row">';
  }
  $i++;
}?>
</div>

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...