我使用此查询来解析来自 flickr 帐户的 JSON 提要,并将来自该提要的最新 12 张照片的代码注入名为#photos 的 div
<script type="text/javascript">
// Set variables needed for query
var URL = "http://api.flickr.com/services/feeds/photos_public.gne";
var ID = "<?php echo get_option('of_flickrid') ?>";
var jsonFormat = "&lang=en-us&format=json&jsoncallback=?";
var ajaxURL = URL + "?id=" + ID + jsonFormat;
// Get the last photos of the flickr account, parse it into HTML code
$.getJSON(ajaxURL, function(data){
var htmlString = '<a href="<?php echo get_option('of_flickr') ?>" target="_blank"><h1><?php echo get_option('of_photostext') ?></h1></a><br class="clear"/>';
// Now start cycling through our array of Flickr photo details
$.each(data.items, function(i,item){
// I only want the ickle square thumbnails
var sourceSquare = (item.media.m).replace("_m.jpg", "_s.jpg");
// Here's where we piece together the HTML
htmlString += '<a href="' + item.link + '" target="_blank">';
htmlString += '<img title="' + item.title + '" src="' + sourceSquare;
htmlString += '" alt="'; htmlString += item.title + '" class="rounded"/>';
htmlString += '</a>';
if(i === 11){
return false;
}
});
// Pop our HTML in the #images DIV
$('#photos').html(htmlString);
}); // End getJSOON
</script>
但我需要加载 12 张随机照片而不是最新的 12 张,我该怎么做?