开发者

flickr phpflickr api

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


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++; ?>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜