私は素晴らしい仕事をしているこの作品を持っています。
(function() {
// What JSON do you want to get? Note: If you're making a request from your own domain to your own domain, delete &callback=?.
var url = 'http://myurl/guest-posts/?category=ffm&format=json&callback=?';
$.getJSON(url).done(function(data) { // Adds the JSON to the data variable.
// Create the HTML string.
var headerContent = '<h1><a href="' + data.website.authenticUrl + '">' + data.website.siteTitle + '</a></h1>';
// Set the HTML.
$('#header').html(headerContent);
$(data.items).each(function() {
var post = '<a href="http://myurl/' + this.fullUrl + '"><h2>' + this.title + '</h2></a><img src= "'+this.assetUrl+'" alt ="'+this.filename+'"><a href="http://myurl/' + this.fullUrl + '">Read More</a>' ;
$('#blog').append(post);
});
});
})();
最新の6件の投稿を表示したい。最新の6つの投稿のみが表示されるようにループする方法がわかりません。それを呼びたい場合は、古い投稿を上書きします。
ATM i には、カテゴリに割り当てられた 3 つの投稿があり、正しい順序で表示されます。タイトル、画像のサムネイル、投稿に移動する続きを読むリンク。
すべてをループするだけなので、常に 6 つの記事しかなく、最新の記事が最初になります。
それが働いている簡単なイメージ。