retrieve list of all labels in blogger

孤者浪人 提交于 2019-12-09 10:16:15

问题


Is there a way to use gdata api to retrieve the list of all labels in a blogger?

I need to create a menu based on that list, but cannot simply list all posts and get it, because it is a busy blog and has more than 2000 posts.


回答1:


Here is the most easy way to get a list of labels by using json call:

<script>
    function cat(json){ //get categories of blog & sort them
        var label = json.feed.category;
        var lst=[];
        for (i=0; i<label.length; i++){
          lst[i] = label[i].term ;  
        }
        alert(lst.sort());  //use any sort if you need that 
    }

</script>

<script src="http://yourblog.blogspot.com/feeds/posts/summary?alt=json&max-results=0&callback=cat"></script>

Just use your blog url.




回答2:


Very simple, I give you two ways

  1. With Javascript API First, you must use:

    <script type="text/javascript" src="http://www.google.com/jsapi"></ script> <script type='text/javascript'>
    google.load("gdata", "1.x", { packages : ["blogger"] });
    </script>

    Second, you can use the code below to retrieve the labels

    postRoot.entry.getCategories()[i].getTerm()

    For more tutorials, you can read from http://www.threelas.com/2012/05/how-to-retrieve-posts-using-blogger.html and http://www.threelas.com/2012/04/basic-blogger-javascript-api.html

  2. With JSON with json, if you want to learn how to retrieve the list of labels, use this object

    json.feed.entry[i].category[j].term

    for more detail tutorials, read from http://www.threelas.com/2012/02/basic-blogger-json-feed-api.html and http://www.threelas.com/2012/09/blogger-json-feed-with-jquery-ajax.html




回答3:


The way I found was using the Blogger's own gadget called Labels. It prints the list of labels and their usage count within some unordered lists(ul) and links(a). You can pull the labels from that after they are loaded using javascript as follows:

$(".list-label-widget-content a").each(function (i, el) {
    var labelText = $(el).text();
    // do what you want with the labels
});

in the end, remove the Labels div element (<div class='widget Label' id='Label1'>)




回答4:


Widget to server the same purpose is provided by bloggers itself.

Widget provides various options like -

  1. You can either show all Labels or choose from your existing List
  2. You can sort the Labels alphabetically or by number of times that label is used (frequency).
  3. You can choose to display these as a List or as a cloud (jumbled).

You can see the same in my blog - Link




回答5:


I don't see a method to get the list of labels in a blog, but you can retrieve all posts (https://developers.google.com/blogger/docs/2.0/json/reference/posts/list) and check the labels field for each of them: https://developers.google.com/blogger/docs/2.0/json/reference/posts#resource




回答6:


First add the JQuery through the following code in console.

var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);

// ... give time for script to load, then type (or see below for non wait option)

   jQuery.noConflict();

Once you are done with this we can take advantage of the JQuery and get the list of labels

Now what I am doing will work for the Blogger Theme Notable and newly added Theme for blogger.

Normally in these themes you will see Labels in the rights side toogle menu of the page.

So What you need it Click on the Label and Click on Show more.

Now Open Browser Debugging console and declare and variable.

var str = "";

Now run the two codes below

1. $('.first-items .label-name').each(function(){str = str + ", "+($(this).text())})
2. $('.remaining-items .label-name').each(function(){str = str + ", "+($(this).text())})
3. str

all the labels you will be get in comma(;) separated format.



来源:https://stackoverflow.com/questions/11057732/retrieve-list-of-all-labels-in-blogger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!