简体   繁体   中英

How to get last elements array in blogger feeds

I'm trying to grab the data feed on my blog with the help of blogger json. I made it with the help of javascript to retrieve the data, but I was confused about displaying the last data in an array of feeds. Whereas what is shown is all the arrays based on the labels in the feeds.

My question: how to show only the last data in an array in blogger feeds.

 function series(e) { for (var t = 0; t < e.feed.entry.length; t++) { var r, l = e.feed.entry[t], n = l.title.$t; if (t == e.feed.entry.length) break; for (var i = 0; i < l.link.length; i++) if ("replies" == l.link[i].rel && "text/html" == l.link[i].type && (l.link[i].title, l.link[i].href), "alternate" == l.link[i].rel) { r = l.link[i].href; break } document.write('<a href="' + r + '" title="' + n + '">' + n + "</a>") } }
 <script src="https://anitoki.malestea.com/feeds/posts/default/-/Horimiya?orderby=published&amp;alt=json-in-script&amp;callback=series&amp;max-results=999"></script>

This code shows only the last entry in the array using arr.slice(-1) , if you meant first element just remove .slice(-1) from the code

function series(response) {
    if (response.feed.openSearch$totalResults.$t > 0) {
        var entry = response.feed.entry.slice(-1)[0],
            title = entry.title.$t,
            url = entry.link.filter(function(e) {
                return e.rel === "alternate";
            })[0].href;

        document.write('<a href="' + url + '" title="' + title + '">' + title + "</a><br/>");

    } else {
        // no posts
    }
}

 function series(e) { var r, l = e.feed.entry[e.feed.entry.length - 1], n = l.title.$t; for (var i = 0; i < l.link.length; i++) { if ("replies" == l.link[i].rel && "text/html" == l.link[i].type && (l.link[i].title, l.link[i].href), "alternate" == l.link[i].rel) { r = l.link[i].href; break } document.write('<a href="' + r + '" title="' + n + '">' + n + "</a>") } }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM