Friday, March 20, 2015

Code to List All Posts of a particular label (category) on my blog

If you want all the posts of a particular label on your blog be listed, so that a viewer can easily click what he wants, this code does just that.
Maybe you wrote some posts that you categorised as fashion, and you want all with that label be listed, follow my guideline as below.

You have an option of

  1. showing or not, a thumbnail for each of the posts
  2. making links open in new tab or not
Now Let's go.
Go straight to the page where you want this to appear and paste the following code.
<script type='text/javascript'>

function listAllPosts(json){
document.write("<div>"+dPostLabel+"</div>")
document.write("<ol>");
var entry = json.feed.entry;
var thumb = false, openNewTab = false
  for(var i=0; i<entry.length; i++){
    try{for(var j=0; j<entry[i].category.length; j++){
      if(entry[i].category[j].term==dPostLabel){
    var pic ='';
    if(thumb){var pic = '<img border="0" height="50" width="50" src="'+ entry[i].media$thumbnail.url + '" /><br />';}
     var p = '<a href="'+ entry[i].link[4].href;
      if(openNewTab){p = p + '" target="_blank';}
       p = p + '">' + pic + entry[i].title.$t +'</a>';
        document.write("<li>"+p+"</li>");}
    }
       }catch(e){}
  }
document.write("</ol></div>");
}
var dPostLabel = "fashionlabel";
</script>

<script src="/feeds/posts/default?max-results=500&amp;alt=json-in-script&amp;callback=listAllPosts"/>
 That's it! Enter your custom values for the values in green colour

If you have used the blogger json code I taught in my {previous post} (for those with more than 500 posts on their blog), you need not include the values in blue color. Just omit it. Instead of the "<script src="/feeds/posts/default?max-results=500&amp;alt=json-in-script&amp;callback=listAllPosts"/>", just write
<script>listAllposts();</script>
hope it works fine for you!

How to fix blogger's atom 500 max results if you use its feed output for some coding

this is for you if
  1. you use blogger
  2. you use blogger atom feed output for coding, either json or json-in-script
  3. you probably have had codes (with javascript) assuming blogger atom maximum output is unlimited
i googled this when i had a similar problem on my other blogger site Lyricsbible.net . All the results say i should use:
http://www.lyricsbible.net/atom.xml?redirect=false&start-index=1&max-results=500
http://www.lyricsbible.net/atom.xml?redirect=false&start-index=501&max-results=500