在 Blogger 上获取带有 JSON 提要的存档
Get Archive with JSON feed on Blogger
我知道有存档小部件,但我想创建自己的小部件并将其作为下拉菜单添加到页面。
有没有办法通过 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&alt=json-in-script&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/>'));
}
}
我知道有存档小部件,但我想创建自己的小部件并将其作为下拉菜单添加到页面。
有没有办法通过 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&alt=json-in-script&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/>'));
}
}