The widget will show an image if it's available. If not it will show 150 letters of text from the article.
What you need
| Account | Description |
| Blogger account | To create and insert the widget |
| Free hosting account | Something like googlepages etc, to host your html file |
Installing the Widget
- Download the single html file here. Extract the hotlinks.html file.
- Log in to blogger and at the dashboard click on new posts, settings, layout etc of your blog. Go to the address box in your browser and get your blogid. It should look something like this
What you are after is the big number after 'blogID=', i.e. your blog-id.http://www.blogger.com/posts.g?blogID=4928424574574982882 - Edit the hotlinks.html - near line 39. Replace the blogid with your blog-id you obtained in the previous step. A full listing of the code can be found at the end of this page.
37. 38. /************************Edit this section with your details*******************/ 39. //The number of links you want to appear. 40. nooflinks=5; 41. //Your blog id 42. blogid="2004095058158627785"; 43. /******************************************************************************/ 44.
- Save this file. You can click on the file. It should load the articles.
- Upload this page to one of your free sites - example: http://www.mysite.com/hotlinks.html.
- Go to layout in your blogger dashboard. Click Add a Gadget and select HTML/JavaScript gadget. Enter the below text into the box. Replace www.mysite.com/hotlinks.html with the place where you uploaded the page. There is no need for a title. Save it.
1. <iframe scrolling="no" 2. frameborder="no" 3. width="100%" 4. src="http://righteous.ninja.googlepages.com/hotlinks.html> 5. </iframe>
- The best place to place this Gadet is on top of your 'Blog Posts' in the layout.
- Save your layout and now view your blog. It should be all good.
1. <html> 2. <head> 3. <title></title> 4. <!--**************************************************************************** 5. * Please feel free to use this code whichever way you feel fit. 6. * But don't forget that Ping Ching aka Righteous thought about it first!!!! 2008 7. * ***************************************************************************--> 8. <style TYPE="text/css"> 9. .hotlinks_href{ 10. font-family:arial; 11. font-size:9px; 12. color:black; 13. font-weight:bold} 14. .hotlinks_summary{ 15. font-family:arial; 16. font-size:9px; 17. color:black;} 18. .hotloading{ 19. font-family:arial; 20. font-size:12px; 21. font-weight:bold;} 22. table{ 23. border-collapse:collapse;} 24. table td{ 25. vertical-align:top;} 26. .hotlink_learn{ 27. color:#808080; 28. font-family:arial; 29. font-size:8px;} 30. </style> 31. <script type="text/javascript" src="http://www.google.com/jsapi"></script> 32. <script> 33. google.load("gdata", "1.s") 34. google.setOnLoadCallback(getMyBlogFeed); 35. var rc=0; 36. var hrefs = new Array(); 37. 38. /************************Edit this section with your details*******************/ 39. //The number of links you want to appear. 40. nooflinks=5; 41. //Your blog id 42. blogid="2004095058158627785"; 43. /******************************************************************************/ 44. 45. function InitContainers(){ 46. var s="<table cellpadding=\"5\" border='0' width='100%'><tr>"; 47. for (i=0;i<nooflinks;i++) 48. s+="<td><div id=\"t"+i+"\"><font class='hotloading'>loading...</font></div></td>"; 49. s+="</tr></table>"; 50. document.getElementById("container").innerHTML=s; 51. } 52. 53. function Draw(r, r2, r3, r4){ 54. var text; 55. if(r3==null) 56. text="<font class=\"hotlinks_summary\">"+r4+"...</font>"; 57. else 58. text="<center><a target=\"_top\" href=\""+hrefs[r]+"\"><img border=\"0\" height=\"90px\" src=\""+r3+"\"/></center>" 59. document.getElementById("t"+rc).innerHTML="<center><a target=\"_top\" href=\""+hrefs[r]+"\" class=\"hotlinks_href\">"+r2+"</a><br/></center>"+text; 60. rc+=1; 61. } 62. 63. function getMyBlogFeed(){ 64. InitContainers(); 65. var bloggerService = new google.gdata.blogger.BloggerService('GoogleInc-jsguide-1.0'); 66. var feedUri = "http://www.blogger.com/feeds/"+blogid+"/posts/full"; 67. var handleBlogPostFeed = function(postsFeedRoot) { 68. var blogTitle = postsFeedRoot.feed.getTitle().getText(); 69. for(i=0 ; i<nooflinks ; i++){ 70. var g=Math.round(postsFeedRoot.feed.getEntries().length*Math.random()); 71. var postEntry = postsFeedRoot.feed.getEntries()[g]; // only get first post 72. var entryUri = postEntry.getSelfLink().getHref(); // post's uri 73. hrefs[postEntry.getId().getValue()] = postEntry.getHtmlLink().getHref(); 74. bloggerService.getBlogPostEntry(entryUri, 75. function(postRoot) { 76. var r3,r4; 77. var postTitle = postRoot.entry.getTitle().getText(); 78. var text=postRoot.entry.getContent().getText(); 79. if((s = text.indexOf("src=\"http://")) != -1 && 80. (e = text.substr(s).toLowerCase().indexOf(".jpg\"")) !=-1){ 81. r3 = text.substring(s+5,s+e+4); 82. } 83. else 84. r3=null; 85. r4=text.substring(0,150); //The amount of text to appear instead of an image 86. Draw(postRoot.entry.getId().getValue(),postTitle, r3, r4); 87. }, 88. handleError 89. ); 90. } 91. }; 92. var handleError = function(error) { 93. }; 94. var query = new google.gdata.blogger.BlogPostQuery("http://www.blogger.com/feeds/"+blogid+"/posts/default"); 95. query.setMaxResults(100); 96. bloggerService.getBlogFeed(query, handleBlogPostFeed, handleError); 97. } 98. </script> 99. </head> 100. <body topmargin="0" leftmargin="0"> 101. <div id="container"></div> 102. </body> 103. </html> 104. |
Back to the tutorial trail | Home

You can download the zipped example here.