Improved Random Post Link Widget for Blogger

The complete instructions and new code for the random post link have been moved to Experiment Garden. Instructions in this post may be outdated, so please see the new version.

The random post link addon for Blogger has now been updated to better and faster than ever before.

Basically this script creates a text link to a random post on your blog. It displays the random post's title as well as a brief random message to accompany it.

The major changes between this updated version and the current version are:

The addon no longer requires the Archive Widget to be added to your page.
The code is no longer limited to displaying posts from the past three months. It can now give you links to posts from your blog's entire history.

You can see the code in action at the top of the post area here at Inkweaver Review. Just refresh the page a few times to see a variety of random links to posts I've written in the past.

Removing Inkweaver Review Advertisment

You may notice that about one out of every ten random links is not to a blog post but back to Inkweaver Review. I would appreciate it if you left this, as it shows appreciation for the time and effort that I went to to create this script. However, you may not like the effect. There are two options you might want to take.

First, you can make the advertisement appear less often by simply adding more of your own custom messages to the list of random messages.

Find the section of code:
var introArray = new Array(
"Have you read ^?",
"Check out ^.",
"Look at ^.",
"Just for you: ^",
"Please look at ^.",
"Would you like to read ^?",
"You might enjoy reading ^.",
"Do you want to read ^?",
"Please read ^.",
"Random link powered by <a href="http://inkweaver-review.blogspot.com/"></a>"
)

To add another message just copy one of the lines in the middle, and paste it again in the middle. If you want to customize the message, just keep in mine that the caret "^" is where the random link is inserted.

If you want to remove the link back to Inkweaver Review completely, just remove the last message in the list. After you remove this message, be sure to remove the comma at the end of the new last message. If you remove the link back to Inkweaver Review then please add another link somewhere. Perhaps add me to your blogroll, or else write a post about the addon with a link to this page.

Limiting Number of Posts Used

Another customization that you may want to do is limiting the number of posts that the script can choose from. As it is the script will display links to any of your posts up to the 99999th post. You may want to limit it to the last 100-200 posts for several reasons. For one thing your oldest posts might be out of date, or their writing quality might not be as good as your new posts. But another reason why you might want to reduce the number of posts is load time. Loading a list of all the posts you have ever written on the blog can be time intensive for older blogs. So to reduce the number of posts that the script will choose from find the number 99999 in the code that you added to the XML template and change it to a smaller number. For example, the number 100 will limit the results to the last 100 posts that you have written.

I sincerely hope that this Blogger addon can be of help to you. If you encounter any issues please let me know by commenting here, and I will do my best to get back to you as soon as possible.

Your Rating:
Inkweaver Review 2009-04-20T15:42:00-05:00

12 replies so far. What are your thoughts?

Shan said...

excellent dear

NathanKP said...

I'm glad that you like it. If you have any problems with it left me know.

selenakyle said...

brilliant! just what i need!
thank you! (i'm keeping your advertisement).

NathanKP said...

Thank you very much Selena. I hope that it works well for you.

If you have any questions or problems installing the code, just ask them here.

Nathan

dennishare said...

LOL :P

Coma said...

This is an elegant older post solution, but I have to ask why it refreshes every few seconds on your page and not on mine?

NathanKP said...

Sorry Coma,

I haven't added instructions on how to create the refreshing post link. I actually created it as an experiment after the fact, and it is actually fairly complicated depending on your blog's theme. Adding the refreshing code to this post is on my list of things to do, but I haven't yet gotten to it.

I'll have to unravel it out of my current code, which drives not only pagination, but also related posts, and random post links.

If you subscribe to the comments on this post, I'll comment when I get it done, and then you'll receive notification and be able to get the updated code with refreshing links.

Do you know ? said...

nice info... thx

NathanKP said...

I hope that it works for you. Once again, let me know if you experience problems with the random post link script.

Indra jaya said...

tanks

Anonymous said...

Hi Nathan,

I was looking for something which randomizes post order. None of my posts are connected so to say and they make for independent reading. So I was looking for something which randomizes the post order everytime the blog is rendered. So hit f5 and you see a different post first. Do you think its possible with Blogger? I'd really like that to work.

Cheers,
Vinod

ASHOK said...

Thanks Man!.

By,
Free Hacking Tricks