🙂
This is the code I’m using right now to pull my entries from 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();
?>
I’d love to have that after 5 entries I can show the others as thumbnails. So I’d like to have 5 enties in standard_resolution and the other.. 10..? 20..? (dunno) as a clickable thumbnail.
Of course I can copy/paste the code again replacing standard_resolution with thumbnail_resolution but how can I specify that I’d like to start from (say) entry 5 instead that entry 0 (to avoid to repeat the same 5 images again before the other ones)? 🙂
Try this: