感谢大家的帮助,请检查是否要查看整个代码处于工作状态:
<?php
/*
Plugin Name: Instagram Feed Embed
Description: Embed a live photo to wordpress posts from your feed
Version: 0.1.0
Author: Jacob Stankaitis
Author URL: https://www.upwork.com/freelancers/~017e31b991d3d0f253
*/
//define Access token
$accesst= "PUT_YOUR_ACCESS_TOKEN_HERE";
//userid
$userid= PUT_YOUR_USER_ID_HERE;
//image count to get
$count=20;
//get api contents
$content = file_get_contents('https://api.instagram.com/v1/users/self/media/recent/?access_token='.$accesst.'&count='.$count);
//converting JSON to object
$standardres = json_decode($content, true);
//array method
$images= array();
foreach($standardres['data'] as $photo) {
$imageData = base64_encode(file_get_contents($photo['images']['standard_resolution']['url']));
array_push ($images, '<img src="data:image/jpeg;base64,' . $imageData . '" />');
}
//create functions for shortcodes with definition
function fone(){
global $images;
return ($images[0]);
}
function ftwo(){
global $images;
return $images[1];
}
function fthree(){
global $images;
return $images [2];
}
function ffour(){
global $images;
return $images [3];
}
function ffive(){
global $images;
return $images [4];
}
function fsix(){
global $images;
return $images [5];
}
function fseven(){
global $images;
return $images [6];
}
function feight(){
global $images;
return $images [7];
}
function fnine(){
global $images;
return $images [8];
}
function ften(){
global $images;
return $images[9];
}
function feleven(){
global $images;
return $images [10];
}
function ftwelve(){
global $images;
return $images [11];
}
function fthirteen(){
global $images;
return $images[12];
}
function ffourteen(){
global $images;
return $images [13];
}
function ffifteen(){
global $images;
return $images [14];
}
function fsixteen(){
global $images;
return $images [15];
}
function fseventeen(){
global $images;
return $images [16];
}
function feighteen(){
global $images;
return $images [17];
}
function fnineteen(){
global $images;
return $images [18];
}
function ftwenty(){
global $images;
return $images [19];
}
//create shortcode
add_shortcode( 'one', 'fone');
add_shortcode( 'two', 'ftwo');
add_shortcode( 'three', 'fthree');
add_shortcode( 'four', 'ffour');
add_shortcode( 'five', 'ffive');
add_shortcode( 'six', 'fsix');
add_shortcode( 'seven', 'fseven');
add_shortcode( 'eight', 'feight');
add_shortcode( 'nine', 'fnine');
add_shortcode( 'ten', 'ften');
add_shortcode( 'eleven', 'feleven');
add_shortcode( 'twelve', 'ftwelve');
add_shortcode( 'thirteen', 'fthirteen');
add_shortcode( 'fourteen' , 'ffourteen');
add_shortcode( 'fifteen', 'ffifteen');
add_shortcode( 'sixteen', 'fsixteen');
add_shortcode( 'seventeen', 'fseventeen');
add_shortcode( 'eighteen', 'feighteen');
add_shortcode( 'nineteen', 'fnineteen');
add_shortcode( 'twenty', 'ftwenty');
?>
如果您想使用它,您可以随意使用,只需将“PUT_YOUR_ACCESS_TOKEN_HERE”和“PUT_YOUR_USER_ID_HERE”替换为您的 Instagram 访问令牌和用户 ID!