1

我想在我的网站上放一个指向我博客的链接,我希望链接看起来像这样:

博客 -最后一篇文章:标题 - 2013 年 6 月 9 日

如何获取上一篇文章的标题和日期?

4

2 回答 2

3

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>
于 2013-06-09T18:32:46.370 回答
2

您的博客很可能支持 RSS。RSS 提供了一个包含您最近更新的 xml 文件,因此您可以使用基于 javascript / jQuery 的解析器来解析此文件并获取您的最后发布日期、标题和链接。

于 2013-06-09T12:44:05.710 回答