简体   繁体   中英

How can I grab the date of the last post on my blogger blog and display it on another site?

I want to put a link to my blog on my website, and I wan the link to look something like this:

Blog - last post: Title - 9-June-2013

How can I grab the title and date of my last post?

Following Alfonso's suggestion, this is the code I've gone for. Where #blogdate is a span element.

<script type="text/javascript">    
google.load("feeds", "1");
function feedLoaded(result) {
    if (!result.error) {
          var pubDate = result.feed.entries[0].publishedDate;
          var date = new Date(pubDate);
          var months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
          var pubDateString = date.getDate() + " " + months[date.getMonth()] + " " + date.getFullYear()
          $('#blogdate').text("last post: '" + result.feed.entries[0].title + "' on " + pubDateString); 
    }
}
function OnLoad() {
   var feed = new google.feeds.Feed(**XML URL**);
   feed.load(feedLoaded);
}
google.setOnLoadCallback(OnLoad);
</script>

It is likely that your blog supports RSS. RSS provides an xml file with your recent updates so you could for example use a javascript / jQuery based parser to parse this file and get your last post date, title and link.

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