I know there is the widget for archive, but I want to create my own and add it to a page as a drop down menu.
Is there a way to get archive months and years count with JSON feed?
In this example: JSFiddle the code retrieve all the posts and then add their date. I removed the posts from showing, but I can't remove the day and repeated date.
<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>
This function will:
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/>'));
}
}
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.