-
Notifications
You must be signed in to change notification settings - Fork 7
/
page-instagram.php
executable file
·51 lines (38 loc) · 1.44 KB
/
page-instagram.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Template Name: Instagram
*/
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // end of the loop. ?>
<!-- http://instagram.com/developer/authentication/ -->
<div class="instagram-list center-content">
<?php
// Supply a user id and an access token
$userid = get_option('instagram_user_id');
$accessToken = get_option('instagram_access_token');
// Gets our data
function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
// Pulls and parses data.
$result = fetchData("https://api.instagram.com/v1/users/".$userid."/media/recent/?access_token=" . $accessToken);
$result = json_decode($result);
?>
<?php foreach ($result->data as $post): ?>
<!-- Renders images. @Options (thumbnail,low_resoulution, high_resolution) -->
<a class="insta-pic" target="_blank" href="<?php echo $post->link ?>"><img src="<?php echo $post->images->low_resolution->url ?>" /></a>
<?php endforeach ?>
</div>
</div><!-- #content .site-content -->
</div><!-- #primary .content-area -->
<?php get_footer(); ?>