views:

207

answers:

3

Overview
I am trying to get a photo feed on to my site using Flickr's api and the phpflickr library. I can successfully get the photoset on to my site, but it shows all the photos from every photoset, what I was hoping to achieve was to show the primary photo from each photoset, and then if the user clicked on the image it would show the full photoset in a lightbox/shadowbox.

My Code

<div id="images" class="tabnav">
                    <ul class="items">
                        <?php $count = 1; ?>
                        <?php foreach ($photosets['photoset'] as $ph_set): ?>
                        <?php $parentID = $ph_set['parent']; ?>
                          <?php $photoset_id = $ph_set['id'];
                          $photos = $f->photosets_getPhotos($photoset_id);
                          foreach ($photos['photoset']['photo'] as $photo): ?>
                           <li>
                           <a rel="shadowbox['<?=$count;?>']" href="<?= $f->buildPhotoURL($photo, 'medium') ?>" title="<?= $photo['title'] ?>">
                                <img src="<?= $f->buildPhotoURL($photo, 'rectangle') ?>" alt="<?= $photo['title'] ?>" width="210" height="160" title="<?= $photo['title'] ?>" />
                                <h3><?=$ph_set['title']?></h3>
                                <p><?=$ph_set['description'];?></p>
                                </a>
                            </li>
                          <?php endforeach; ?>
                        <?php $count++; ?>
                        <?php endforeach; ?>
                    </ul>
                </div>

Another Attempt

I have also tried calling the getPhotos function differently, instead of sending it without any parameters I sent it with parameters

$photos = $f->photosets_getPhotos($photoset_id, NULL, NULL, 1, NULL);

The above code stopped the showing all the photos from each photoset and started showing just the primary image, but it also stopped making the rest of the photos accesible to me.

Is there something I can do to make this work? I am totally out iof ideas.

Regards and thanks

A: 

What you'll probably want to do is starting by iterating through the whole array and grouping each album into a separate array first and making a special array for your album's main photo.

Then you can easily iterate through the arrays to display each album and the code becomes much more maintainable.

arnorhs
Your was the correct way of doing this, mine answer is a hack, for this reason I am going to mark you up and give you the answer
sea_1987
A: 

I came up with this soltion, thought I would post it in case anyone else hits this problem,

<?php $count = 1; ?>
<?php foreach ($photosets['photoset'] as $ph_set): ?>
<?php $parentID = $ph_set['parent']; ?>
<li>
     <?php $photoset_id = $ph_set['id'];
     $photos = $f->photosets_getPhotos($photoset_id);
         foreach ($photos['photoset']['photo'] as $photo): ?>
             <?php if($parentID == $ph_set['parent']): ?>
             <a rel="lightbox[album<?=$count;?>]" href="<?= $f->buildPhotoURL($photo, 'medium') ?>" title="<?= $photo['title'] ?>">
         <?php endif;?>
         <img src="<?= $f->buildPhotoURL($photo, 'rectangle') ?>" alt="<?= $photo['title'] ?>" width="210" height="160" title="<?= $photo['title'] ?>" />
             <h3><?=$ph_set['title']?></h3>
         <?php if($ph_set['description'] != null) :?>
             <p><?=$ph_set['description'];?></p>
         <?php endif; ?>
         <?php if($parentID == $ph_set['parent']): ?>
                 </a>
        <?php endif;?>
<?php endforeach; ?>
</li>
<?php $count++; ?>

sea_1987
A: 

I tried using your code but got this error:

Parse error: syntax error, unexpected $end in ../photos.php on line 87

Michael
Your missing an <? endforeach; ?> right at the end, my poor copy and paste skills, sorry
sea_1987
thank you! I managed to get the photos to show up, and the lightbox goes through the photoset photos, but not just the primary photo thumbnails show up, every photo from every set does.
Michael
I go rounnd that using CSS
sea_1987