Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrieve list of all labels in blogger

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.

like image 718
Johnny Everson Avatar asked Jun 15 '12 20:06

Johnny Everson


3 Answers

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.

like image 89
Mina Avatar answered Sep 21 '22 19:09

Mina


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

like image 39
Putri Arisnawati Avatar answered Sep 17 '22 19:09

Putri Arisnawati


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'>)

like image 43
Johnny Everson Avatar answered Sep 17 '22 19:09

Johnny Everson