1

Im using this to display a list of thumnails called from my cms:

<?php if($gallery_images) { ?>
<?php
$slide_page = 1;
foreach($gallery_images as $count => $image) { ?>
<li><a href="<?php echo $image->getResizedImage(); ?>" rel="example1"  title="********"><img width="125" height="80" src="<?php echo $image->getThumbnailImage()     
?>" /></a></li>

     <?php if(($count+1) % 3 == 0) {
     $slide_page += 1;
      ?>

It calls images from within my CMS and displays them in groups of 3, with some added jquery to scroll through the sets.

What im trying to do is merge this with my videos within the same list.

The video code is as follows:

<?php foreach($videos as $count => $video) { ?>
<a href="<?php echo $video->getLocation(); ?>" class="videolink"><img src="{thumbnail}" />Video A</a>
<?php } ?> 

Ive tried using the array_merge function but seem to be having difficulties any help would be greatly appreciated

1
  • 1
    array_merge is pretty straightforward. You pass in any number of arrays and it will return one merged array. Please point out where you are having difficulties. Commented Jan 19, 2011 at 16:56

1 Answer 1

1

It's easy:

foreach (array_merge($gallery_images, $videos) as $count => $value) { }

You may also want to look at array_chunk().


Update:

<? foreach (array_merge($images, $videos) as $key => $value): ?>
    <? if (is_object($value) === true): ?>
        <? if (method_exists($value, 'getLocation') === true): ?>
            <a href="<?= $video->getLocation(); ?>" class="videolink"><img src="{thumbnail}" />Video A</a>
        <? elseif (method_exists($value, 'getResizedImage') === true): ?>
            <a href="<?= $image->getResizedImage(); ?>" rel="example1"  title="***"><img width="125" height="80" src="<?= $image->getThumbnailImage(); ?>" /></a>
        <? endif; ?>
    <? endif; ?>
<? endforeach; ?>
Sign up to request clarification or add additional context in comments.

2 Comments

@Christian: What is the problem then?
should of made things clearer, the issue is that the $value is different for both variables so $gallery_images - $image and $videos - $video as well as the the source of the thumbnail produced as images uses an thumbnail (so the image at hand however re-sized and the video will call an image from file, as cant produce a thumb from the same pretenses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.