Created
October 20, 2014 08:28
-
-
Save tormjens/ac80b13885a6205b5e4f to your computer and use it in GitHub Desktop.
Instagram function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function lhk_instagram_feeds($limit = 6) { | |
$tags = array( 'levangerhk' ); | |
$images = get_transient( 'lhk_instagram' ); | |
if( $images === false ) { | |
$images = array(); | |
foreach($tags as $tag) { | |
$data = file_get_contents('https://api.instagram.com/v1/tags/'.$tag.'/media/recent?client_id=d5eb3a4d30224d088e98d8b1ceae2348&count=10'); | |
$data = json_decode($data); | |
$data = $data->data; | |
foreach($data as $data) { | |
$images[] = array( | |
'thumbnail' => $data->images->thumbnail, | |
'standard' => $data->images->standard_resolution, | |
'date' => $data->created_time, | |
'url' => $data->link | |
); | |
} | |
} | |
$sortArray = array(); | |
foreach($images as $person){ | |
foreach($person as $key=>$value){ | |
if(!isset($sortArray[$key])){ | |
$sortArray[$key] = array(); | |
} | |
$sortArray[$key][] = $value; | |
} | |
} | |
$orderby = "date"; //change this to whatever key you want from the array | |
array_multisort($sortArray[$orderby],SORT_DESC,$images); | |
set_transient( 'lhk_instagram', $images, 60 * 60 * 12 ); | |
} | |
$images = array_slice($images, 0, $limit); | |
return $images; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment