如何在Blogger上列出具有特定标签的所有帖子的帖子标题?

时间:2018-06-12 18:43:26

标签: javascript list tags blogger

如何列出博客上具有特定标签的所有帖子的帖子标题?

在这个问题的答案中解释了相同的排序顺序: How to change this code to list post titles of all the post on Blogger in format YYYY.MM.DD and chronological order?

我尝试制作一个页面,列出不同标题(标签)下的帖子标题。

1 个答案:

答案 0 :(得分:0)

您可以使用以下网址按标签获取帖子(将LabelName替换为您的标签)

/feeds/posts/summary/-/LabelName?alt=json

旧问题的代码

<div>
<ul id="postList12"></ul>
</div>
<script type="text/javascript">
var startIndex = 1;
var maxResults = 150;
var allResults = [];
function sendQuery12()
{
   var scpt = document.createElement("script");
   scpt.src = "/feeds/posts/summary/-/LabelName?alt=json&callback=processPostList12&start-index=" + startIndex + "&max-results=" + maxResults;
   document.body.appendChild(scpt);
}

function printArrayResults(root)
{  
   var elmt = document.getElementById("postList12");
    for (index = 0; index < allResults.length; index++) {
         elmt.appendChild(allResults[index]);
    }
}

function processPostList12(root)
{    
  var elmt = document.getElementById("postList12");
   if (!elmt)
      return;

   var feed = root.feed;

   if (feed.entry.length > 0)
   {
      for (var i = 0; i < feed.entry.length; i++)
      {
         var entry = feed.entry[i];
         var title = entry.title.$t;
         var date = entry.published.$t

         for (var j = 0; j < entry.link.length; j++)
         {
            if (entry.link[j].rel == "alternate")
            {
               var url = entry.link[j].href;
               if (url && url.length > 0 && title && title.length > 0)
               {
                  var liE = document.createElement("li");
                  var a1E = document.createElement("a");
                  a1E.href = url;
                  a1E.textContent = title + " (" + date.substr(0,10) + ")";
                  liE.appendChild(a1E);
                  //elmt.appendChild(liE);
                  allResults.push(liE);
               }
               break;
            }
         }
      }
      if (feed.entry.length >= maxResults)
      {
         startIndex += maxResults;
         sendQuery12();
      } else {
         printArrayResults();
      }
   }
}
sendQuery12();
</script>