Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

php - Display photos from Flickr in a responsive grid


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Add the following styles first

* {
      box-sizing: border-box;
    }

    body {
      margin: 0;
      font-family: Arial;
    }

    .header {
      text-align: center;
      padding: 32px;
    }

    .row {
      display: -ms-flexbox; /* IE10 */
      display: flex;
      -ms-flex-wrap: wrap; /* IE10 */
      flex-wrap: wrap;
      padding: 0 4px;
    }


    .column {
      -ms-flex: 25%; /* IE10 */
      flex: 25%;
      max-width: 25%;
      padding: 0 4px;
    }

    .column img {
      margin-top: 8px;
      vertical-align: middle;
      width: 100%;
    }


    @media screen and (max-width: 800px) {
      .column {
        -ms-flex: 50%;
        flex: 50%;
        max-width: 50%;
      }
    }


    @media screen and (max-width: 600px) {
      .column {
        -ms-flex: 100%;
        flex: 100%;
        max-width: 100%;
      }
    }

Here is the the modified Code for you

 <?php
    //FLICKR IMPLEMENTATION
    $tag = "southampton";
    $url = 'https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=499ff1d1566f49b580c2a5e9289f9e9d&tags='.$tag.'&sort=interestingness-desc&format=json&nojsoncallback=1';
    $data = json_decode(file_get_contents($url));
    $photos = $data->photos->photo;
        
    $count = 1;
     echo '<div class="row">';
    foreach ($photos as $photo){           
        
        $url = 'http://farm'.$photo->farm.'.staticflickr.com/'.$photo->server.'/'.$photo->id.'_'.$photo->secret.'.jpg';
        
         if($count % 4 == 1){
             echo '<div class="column">';
          }
            echo '<img src="'.$url.' style="width:100%"/>';
        
         if($count % 4 == 0){
              echo "</div>";
         } 
    
         $count++;
         
    }
    echo "</div>";
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...