我正在尝试根据标签显示特定的 tumblr 帖子。
苦苦挣扎:1.如何查询tumblr的多个标签?-- (这里有一个类似的帖子:如何在 Tumblr 的 read api 中查询多个标签?) -- 但是我如何使它适应我的脚本呢?2. 根据标签为呈现的帖子分配一个类。例如,如果帖子被标记为“featured_1”,它应该在呈现的 html 中显示“featured_1”类。
提前谢谢了!任何帮助表示赞赏。
这是我正在使用的脚本:
/*
--------------------------------------
Created by james <at> bandit.co.nz
http://blog.bandit.co.nz
*/
Featured = {
'apiNum' : 100, // how many posts to read
'listId' : 'featured', // the id of the ul to write to
'tagName' : 'featured', // the name of the tag we're searching for
'tagName2': 'featured_1',
'tagName3': 'featured_2',
'tagName4': 'featured_3',
'postDB' : [],
'listPos' : 0,
'doList' : function (where) {
var li; var ul = $('#'+where);
var titles = {"link":"link-text", "photo":"photo-caption", "quote":"quote-text", "regular":"regular-body", "video":"video-caption"}
// cycle through post database
pcount = Featured.postDB.length;
for(i=Featured.listPos;i<pcount;i++) {
p = Featured.postDB[i];
if(p[titles[p.type]] != '') titlestr = p[titles[p.type]].replace(/<\/?[^>]+>/gi, '');
else titlestr = p['url'];
li = document.createElement('li');
$(li).html('<p class=" ">'+titlestr+'</p>');
ul.append(li);
Featured.listPos = pcount;
}
},
'getData' : function() {
$.get('/api/read/json?num='+Featured.apiNum+'&tagged='+Featured.tagName3+Featured.tagName+Featured.tagName2,
function(data) {
eval(data);
for(i=0;i<tumblr_api_read.posts.length;i++) {
Featured.postDB.push(tumblr_api_read.posts[i]);
Featured.doList(Featured.listId);
}
}
);
}
};
$(document).ready(function(){
Featured.getData();
});