Blogger:使用 JSON 回调获取标签 post

Blogger: Fetch label post using JSON callback

我尝试使用博主 json 回调来获取数据。使用以下 java 脚本代码,我可以获得标题、link、缩略图、摘要和 label/category。除了 label/category 之外,一切都很好。不幸的是,我只显示了一个标签。如何循环浏览博主 post 的每个 post 标签? post不仅有一个标签,还有2个或3个标签。

代码如下:

var numposts = 5;
function whatshot(json) {
    for (var i = 0; i < numposts; i++) {
        var entry = json.feed.entry[i];
        var posttitle = entry.title.$t;
        var category = entry.category[0].term;
        var summary = entry.summary.$t;
        var category;
        var posturl;
        var thumb = entry.media$thumbnail.url;
        var thumb = thumb.replace("s72-c", "s1600");
        if (i == json.feed.entry.length) break;
        for (var k = 0; k < entry.link.length; k++) {
            if (entry.link[k].rel == 'alternate') {
                posturl = entry.link[k].href;
                break;
            }           
        }               
        document.write('<ul class="collection top-highlight"><li class="collection-item avatar"><img class="circle" src="'+thumb+'"/><span class="title">Lipsum</span><p>'+category+'</p></li><li><p class="sp-status">'+summary+'</p></li><li><img class="responsive-img" src="'+thumb+'"/></li><li><h2 class="sp-title"><a href="'+posturl+'">'+posttitle+'</a></h2></li></ul>');
    }
}

使用 for 循环遍历类别项并获取所有 post 个标签

for (var m = 0; m < entry.category.length; m++) {
    category += entry.category[m].term + " ";
}

在每个标签名称后注释 space

这是您的代码

var numposts = 5;
function whatshot(json) {
    for (var i = 0; i < numposts; i++) {
        var entry = json.feed.entry[i];
        var posttitle = entry.title.$t;
        var summary = entry.summary.$t;
        var category;
        for (var m = 0; m < entry.category.length; m++) {
            category += entry.category[m].term + " ";
        }
        var posturl;
        var thumb = entry.media$thumbnail.url;
        var thumb = thumb.replace("s72-c", "s1600");
        if (i == json.feed.entry.length) break;
        for (var k = 0; k < entry.link.length; k++) {
            if (entry.link[k].rel == 'alternate') {
                posturl = entry.link[k].href;
                break;
            }           
        }               
        document.write('<ul class="collection top-highlight"><li class="collection-item avatar"><img class="circle" src="'+thumb+'"/><span class="title">Lipsum</span><p>'+category+'</p></li><li><p class="sp-status">'+summary+'</p></li><li><img class="responsive-img" src="'+thumb+'"/></li><li><h2 class="sp-title"><a href="'+posturl+'">'+posttitle+'</a></h2></li></ul>');
    }
}