正如標題所示,是否可以將我的博客的最新帖子嵌入到網站的主index.html中?如何將最新博客帖子嵌入到index.html中?
網站主頁是https://my-domain.com/index.html和博客https://blog.my-domain.com。我想將最新的博客帖子嵌入到我網站主頁上的特定位置。即當我發佈博客時,主頁面會自動更新。
這可能嗎?
正如標題所示,是否可以將我的博客的最新帖子嵌入到網站的主index.html中?如何將最新博客帖子嵌入到index.html中?
網站主頁是https://my-domain.com/index.html和博客https://blog.my-domain.com。我想將最新的博客帖子嵌入到我網站主頁上的特定位置。即當我發佈博客時,主頁面會自動更新。
這可能嗎?
您可以使用您的博客JSONP,對於最新發生後創建的div像這樣<div id="latest-post"></div>
<script src='http://your-blog.com/feeds/posts/default?alt=json-in-script&callback=latestPost' async='async'></script>
<script>
function latestPost(json) {
var entry = json.feed.entry;
for(var i = 0; i < entry.length; i++) {
var link, title = entry[i].title.$t;
for(var j = 0; j < entry[i].link.length; j++) {
if(entry[i].link[j].rel === "alternate") {
link = entry[i].link[j].href;
}
document.getElementById("latest-post").innerHTML += "<a href='" + link + "'>" + title + "</a>";
}
}
}
</script>
絕對可能,但請張貼您當前嘗試的代碼。 –
是必要的嗎?我是新來的編碼,所以我不知道該怎麼做。但是,謝謝你回答我的問題,我一定會找到辦法做到這一點。 :) – Duaney
有人嗎?請? – Duaney