Created
November 6, 2015 17:18
-
-
Save jcanfield/05c8e0bf65febb30bc5e to your computer and use it in GitHub Desktop.
Instagram API to display recent photos in WordPress
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
// Modifications via StackOverflow | |
You are receiving the data in the right order, but then you are using the shuffle() function on the images array $a_images you created . | |
if you remove the shuffle($a_images); from your code it'll be just fine. | |
and replace $image[link], $image[url] and // // $image[caption] with $image['link'], $image['url'] and $image['caption'] | |
sorry for bad english |
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
up vote | |
1 | |
down vote | |
favorite | |
Instagram API to Wordpress - Recent Photos Aren't Most Recent | |
wordpress instagram | |
I've got this working to pull recent Instagram posts into Wordpress, however the "recent" photos that are displayed aren't actually my most recent Instagram posts. When I refresh, the Instagram posts that are pulled in also change. I can only find a max/min time within the API docs. Is there any way to just get the last 3 Instagram posts made? | |
<?php | |
$json = file_get_contents('https://api.instagram.com/v1/users/user-id/media/recent/?access_token=key-number'); | |
$a_json = json_decode($json, true); | |
foreach( $a_json['data'] as $key => $value) { | |
$a_images[$value['id']]['link'] = $value['link']; | |
$a_images[$value['id']]['url'] = $value['images']['standard_resolution']['url']; | |
$a_images[$value['id']]['caption'] = $value['caption']['text']; | |
} | |
shuffle($a_images); | |
echo '<ul>'; | |
$i = 0; | |
foreach($a_images as $image) { | |
if ($i < 3) { | |
echo '<li class="large-4 columns"> | |
<div class="front"> | |
<a href="'.$image[link].'" target="_blank"> | |
<img src="'.$image[url].'"/> | |
</a> | |
</div> | |
<div class="back"> | |
<p>'.$image[caption].'</p> | |
</div> | |
</li>'; | |
$i++; | |
} | |
} | |
echo '</ul>'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment