Finally, My blog got rid of bx-error codes.. come back soon and read the tutorial...
TopBottom

How to show 10 posts instead of 5 posts in blogger

Posted by Nitesh Kothari at 17 October 2008 | Post views: counter
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

One of the most popular and useful blogger hack or blogger widget is Recent Posts. This blogger hack lets you display recent posts of your blog. Maximum number of bloggers use blogger feed for this purpose. But, this method one limitation, i.e. only 5 most recent posts can be displayed. I had promised my readers that Wolverine Hacks will have a new look soon.While designing a new template for Wolverine Hacks, I planned to have a widget which can display 10 most recent posts.


How to show 10 recent posts

I tried to edit the blogger code to make this possible but all in vain. Thus, I used JavaScript to show more than 5 recent posts. Here is the code:

<script>
function rp(json) {
document.write('<ul>');

for (var i = 0; i < numposts; i++) {
document.write('<li>');
var entry = json.feed.entry[i];
var posttitle = entry.title.$t;
var posturl;

if (i == json.feed.entry.length) break;

for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == 'alternate') {
posturl = entry.link[k].href;
break;
}
}

posttitle = posttitle.link(posturl);
var readmorelink = "(more)";
readmorelink = readmorelink.link(posturl);
var postdate = entry.published.$t;
var cdyear = postdate.substring(0,4);
var cdmonth = postdate.substring(5,7);
var cdday = postdate.substring(8,10);
var monthnames = new Array();
monthnames[1] = "Jan";
monthnames[2] = "Feb";
monthnames[3] = "Mar";
monthnames[4] = "Apr";
monthnames[5] = "May";
monthnames[6] = "Jun";
monthnames[7] = "Jul";
monthnames[8] = "Aug";
monthnames[9] = "Sep";
monthnames[10] = "Oct";
monthnames[11] = "Nov";
monthnames[12] = "Dec";

if ("content" in entry) {
var postcontent = entry.content.$t;
} else if ("summary" in entry) {
var postcontent = entry.summary.$t;
} else
var postcontent = "";
var re = /<\S[^>]*>/g;
postcontent = postcontent.replace(re, "");
document.write(posttitle);

if (showpostdate == true) document.write(' - ' + monthnames[parseInt(cdmonth,10)] + ' ' + cdday);

if (showpostsummary == true) {
if (postcontent.length < numchars) {
document.write(postcontent);
} else {
postcontent = postcontent.substring(0, numchars);
var quoteEnd = postcontent.lastIndexOf(" ");
postcontent = postcontent.substring(0,quoteEnd);
document.write(postcontent + '...' + readmorelink);
}
}
document.write('</li>');
}
document.write('</ul>');

}
</script>

<script>
var numposts = 10;
var showpostdate = false;
var showpostsummary = false;
var numchars = 100;
</script>

<script src="http://YOURBLOG.blogspot.com/feeds/posts/default?orderby=published&alt=json-in-script&callback=rp"></script>

<div class="clear"></div><p style="text-align:right;"><a href="http://feeds.feedburner.com/~r/wolverinehacks/~3/423845145/how-to-show-10-posts-instead-of-5-posts.html" title="Grab this wiget">Grab this Widget</a></p>

If you want to use this blogger hack, just copy this code to a new HTML/Javascript Gadget.

Final Words

I hope you will find it useful for your blog. Give it a try and leave your feedback or query here. What do you want me to write next?

25 comments:

Wolverine said...

i posted this blogger hack some hours back and its there on blogger templates blog... check widget section at right sidebar here: http://blogger-templates.blogspot.com

Anshul said...

Use simple codes here you can show 50 posts

http://anshuldudeja.blogspot.com/2008/10/recent-posts-widget-for-blogger.html

Wolverine said...

i appreciate your effort... but using this code also you can show 50 posts.. just change this:
var postshow=10; change no. 10 whatever no you want... n those many posts will be displayed

Taylor said...

Hey man. Awesome hack. Thanks for the blog comment on Video Blogging Tips. I greatly appreciate it. Keep up the good work on your blog. Already subscribe. Thanks man! Keep in touch!

Rohit said...

Nice findings,
Actually, this gives links like yoursite.com/feeds/../..
Instead Blogger users can use the Customizable recent posts widgets for blogger/blogspots From here : http://blogsolute.com/2007/12/recent-posts-widget-for-your-blog.html

This gives direct links to you posts and adds to your backlinks than giving feed links.

AD said...

Wow, great hack with the blogger code itself.
Keep 'em coming like these.

•▬●๋•p.k.áŕừń●๋•▬• said...

Is there any hack for showing 10comments in a blogspot...


www.hacking2all.blogspot.com

Nitesh Kothari said...

yes you can show 10 recent comments using same code...just find this line:
<script src="http://YOURBLOG.blogspot.com/feeds/posts/default?orderby=published&alt=json-in-script&callback=rp"></script>

and replace "posts" to "comments"

•▬●๋•p.k.áŕừń●๋•▬• said...

Thanks man it worked great on my blog i.e www.hacking2all.blogspot.com

can u post how to show popular post in blogspot(10posts)

RANJINAP said...

I used this(Almost same) already from another place useful widget,But a small Disadvantage is Loading takes long time.

Thanks Lot Nithesh

Znipers said...

How to add "Most Popular" like your on the top right there? I think it is a most people read topic right? how do we adapted in your template?

thank in advanced.

richard beck said...

I follow hello everyone, I just submmited in this website, its cool here you can make money easy by hosting videos , any doubt can check in the flash pie, the web is www.vismomedia.com

Erotic Horizon said...

Beautiful...

This works perfectly, have tried others nothing works...

this is perfect.

E.H>

learn how to play blackjack online said...

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me.Really the blogging is spreading its wings rapidly

Guida al black jack said...

Really i am impressed from this post....the person who create this post he is a great human..thanks for shared this with us.i found this informative and interesting blog so i think so its very useful and knowledge able.

english courses in london said...

Its always good to learn tips like you share for blog posting. As I just started posting comments for blog and facing problem of lots of rejections. I think your suggestion would be helpful for me. I will let you know if its work for me too.
Thanks and keep post such a informative blogs.

plumber newtown said...

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

Post a Comment

Thank you for commenting at NiteshKothari.com. I follow "U comment I comment" movement. All the comment are dofollow. Please do not spam or leave meaningless or short comments. I expect you to leave me meaningful, relative and genuine comments. Thank you.

Blog Widget by LinkWithin