在查询某些帖子的tumblr API后,我无法为tumblr标签分配特定的css值。
让我们说这些帖子被标记为“圆圈”,“方形”,“线条”。我想要做的是,当每个帖子显示时,它会得到一个相应的css类:“。circle”,“。sqquare”,“。line”。目前我能够发布帖子(但我对tumblr来说还是新手)。
问题1:如何为每个帖子设置一个css值? 问题2:如何将显示的帖子限制为特定div中的单个帖子?
非常感谢提前。我正在使用的代码如下所示。
谢谢!
/*
--------------------------------------
Based on code from 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' : 'circle', // the name of the tag we're searching for
'tagName2' : 'square',
'tagName3' : 'line',
'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(tag) {
return $.get('/api/read/json?num=' + Featured.apiNum + '&tagged=' + tag,
function(data) {
for(i=0;i<tumblr_api_read.posts.length;i++) {
Featured.postDB.push(tumblr_api_read.posts[i]);
}
}
);
},
'multipleQueries' : function() {
$.when(Featured.getData(Featured.tagName), Featured.getData(Featured.tagName2), Featured.getData(Featured.tagName3), Featured.getData(Featured.tagName4) )
.then(function() {
Featured.doList(Featured.listId);
});
},
};
$(document).ready(function(){
Featured.multipleQueries()
Featured.getData()
});