gpt4 book ai didi

javascript - 在 Blogger 上使用 JSON feed 获取存档

转载 作者:行者123 更新时间:2023-11-28 06:56:17 26 4
gpt4 key购买 nike

我知道有用于存档的小部件,但我想创建自己的小部件并将其作为下拉菜单添加到页面中。

有没有办法使用 JSON feed 获取存档月份和年份?

在此示例中:JSFiddle该代码检索所有帖子,然后添加它们的日期。我已将帖子从显示中删除,但无法删除日期和重复日期。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
function LoadTheArchive(TotalFeed) {
var PostTitles = new Array();
var PostURLs = new Array();
var PostYears = new Array();
var PostMonths = new Array();
var PostDays = new Array();
if ("entry" in TotalFeed.feed) {
var PostEntries = TotalFeed.feed.entry.length;
for (var PostNum = 0; PostNum < PostEntries; PostNum++) {
var ThisPost = TotalFeed.feed.entry[PostNum];
PostTitles.push(ThisPost.title.$t);
PostYears.push(ThisPost.published.$t.substring(0, 4));
PostMonths.push(ThisPost.published.$t.substring(5, 7));
PostDays.push(ThisPost.published.$t.substring(8, 10));
var ThisPostURL;

}
}
DisplaytheTOC(PostTitles, PostURLs, PostYears, PostMonths, PostDays);
}

function DisplaytheTOC(PostTitles, PostURLs, PostYears, PostMonths, PostDays) {
var MonthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var NumberOfEntries = PostTitles.length;
for (var EntryNum = 0; EntryNum < NumberOfEntries; EntryNum++) {
NameOfMonth = MonthNames[parseInt(PostMonths[EntryNum], 10) - 1]
document.write("(" + NameOfMonth + " " + parseInt(PostDays[EntryNum], 10) + ", " + PostYears[EntryNum] + ")<br />");
}
}
</script>
<script src="http://mylifeaslucille.blogspot.com/feeds/posts/default?max-results=500&amp;alt=json-in-script&amp;callback=LoadTheArchive">
</script>

最佳答案

该函数将:

function LoadTheArchive(TotalFeed) 
{
var resultArr = new Array();
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
if ("entry" in TotalFeed.feed)
{
for (i in TotalFeed.feed.entry)
{
var thisPost = TotalFeed.feed.entry[i];
var dateObj = new Date(thisPost.published.$t);
var element = "(" + months[dateObj.getMonth()] + ", " + dateObj.getFullYear() + ")<br />";
if(resultArr.indexOf(element) == -1) resultArr.push(element);
}
document.write(resultArr.join('<br/>'));
}
}

关于javascript - 在 Blogger 上使用 JSON feed 获取存档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32545145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com