0

:) 这是我现在用来从 Instagram 提取我的条目的代码:

        <?php
        setlocale(LC_TIME, 'it_IT');
        function get_instagram($tag=bombacarta,$count=10,$width=612,$height=612){
            $url = 'https://api.instagram.com/v1/tags/'.$tag.'/media/recent/?access_token=13137.f59def8.1a759775695548999504c219ce7b2ecf&count='.$count;
            // Also Perhaps you should cache the results as the instagram API is slow
            $cache = './wp-content/themes/raymond-31/instagram_json/'.sha1($url).'.json';
            if(file_exists($cache) && filemtime($cache) > time() - 500){
                // If a cache file exists, and it is newer than 1 hour, use it
                $jsonData = json_decode(file_get_contents($cache));
            } else {
                $jsonData = json_decode((file_get_contents($url)));
                file_put_contents($cache,json_encode($jsonData));
            }
            $result = '<div style="border-top:1px solid #ddd">'.PHP_EOL;
            foreach ($jsonData->data as $key=>$value) {
                $location = (!empty($value->location->name))?'presso '.$value->location->name:null;
                $result .= "\t".'<em>'.htmlentities($value->caption->text, ENT_QUOTES, "UTF-8").'</em><br /><img src="'.$value->images->standard_resolution->url.'" alt="'.htmlentities($value->caption->text, ENT_QUOTES, "UTF-8").'" width="'.$width.'" height="'.$height.'" /><br /><div class="postinfo">Scattata da '.$value->caption->from->full_name.' il '.htmlentities(gmstrftime('%e %B %Y alle %R', $value->caption->created_time + 7200)).' '.htmlentities($location).'</div><br />'.PHP_EOL;
            }
            $result .= '</div>'.PHP_EOL;
            return $result;
        }
        echo get_instagram();
        ?>

我很想在 5 个条目后将其显示为缩略图。所以我想在standard_resolution中有5个实体,另一个.. 10..?20..?(不知道)作为可点击的缩略图。

当然,我可以再次复制/粘贴代码,用 thumbnail_resolution 替换 standard_resolution 但我如何指定我想从(比如说)条目 5 而不是条目 0 开始(以避免在其他图像之前再次重复相同的 5 个图像)? :)

4

1 回答 1

1

试试这个:

  function get_instagram($tag=bombacarta,$count=10,$width=612,$height=612){
            $url = 'https://api.instagram.com/v1/tags/'.$tag.'/media/recent/?access_token=13137.f59def8.1a759775695548999504c219ce7b2ecf&count='.$count;
            // Also Perhaps you should cache the results as the instagram API is slow
            $cache = './wp-content/themes/raymond-31/instagram_json/'.sha1($url).'.json';
            if(file_exists($cache) && filemtime($cache) > time() - 500){
                // If a cache file exists, and it is newer than 1 hour, use it
                $jsonData = json_decode(file_get_contents($cache));
            } else {
                $jsonData = json_decode((file_get_contents($url)));
                file_put_contents($cache,json_encode($jsonData));
            }
            $result = '<div style="border-top:1px solid #ddd">'.PHP_EOL;
            $ic=0;
            foreach ($jsonData->data as $key=>$value) {
                $location = (!empty($value->location->name))?'presso '.$value->location->name:null;
if($ic>=5){$res_c=thumbnail_resolution; $x_data="TESTT";}else{$res_c=standard_resolution;$x_data='Scattata da '.$value->caption->from->full_name.' il '.htmlentities(gmstrftime('%e %B %Y alle %R', $value->caption->created_time + 7200)).' '.htmlentities($location);}
$ic++;
                $result .= "\t".'<em>'.htmlentities($value->caption->text, ENT_QUOTES, "UTF-8").'</em><br /><img src="'.$value->images->$res_c->url.'" alt="'.htmlentities($value->caption->text, ENT_QUOTES, "UTF-8").'" width="'.$width.'" height="'.$height.'" /><br /><div class="postinfo">'.$x_data.'</div><br />'.PHP_EOL;
            }
            $result .= '</div>'.PHP_EOL;
            return $result;
        } 
于 2012-04-22T13:15:09.600 回答