Translate

Sunday, July 22, 2012

HOW TO MAKE RANDOM POST SUPER SPEED

This widget is used to display random posts from the blog you want. Different to the commonly encountered random post, this widget uses a slightly different way to display a random post and definitely super fast.

Random post widget that will generally do several times a randomization based on the number of posts. If there is post number 10, there will be 10 times the random process at the same time and also performed 10 times a request to the relevant RSS feeds.

While random post widget that I want to share will only do a 1 time and then displays the total number of posts is determined by the recent post.

So you could say this widget is a semi-random post widget while the other is called the full-random post. But the goal remains the same, showing a different post each time the refresh

There are two versions of the widget is the single request version which is a lot simpler and faster and there is also the double request version which is a more precise but slower than version 1.

Version 1
Paste this script will display a random place you post. The results displayed in list form.

<script type="text/javascript">
var random = Math.floor (Math.random () * 100);
ttal var = 10;
recentpostslist function (json) {
document.write ("<ul>")
for (var i = 0; i <json.feed.entry.length; i + +)
{
for (var j = 0; j <json.feed.entry [i]. link.length; j + +) {
if (json.feed.entry [i]. link [j]. rel == 'alternate') {
break;
}
}
entryUrl var = "'" + json.feed.entry [i]. link [j]. href + "'";
json.feed.entry entryTitle = var [i]. title. $ t;
var item = "+ <a href="+ entryUrl'" target="_blank"> 'entryTitle + +" </ a> </ li> ";
document.write (item);
}
document.write ('</ ul>');
}
document.write ("<script

</ Script>

Description:
- Adjusted total number 100 blog posts - the number of posts you want to display.
- Figure 10 to determine the number of posts that appear at random post.

- Change-tutorial-interesting blog with a blog address that you want.

Excess
Loading time is very fast because only one time request to the RSS feed.

Weakness
Not all posts are within random post.
For example if there are 1000 blog post, but his post was just given a random value of 500, then 500 new posts that will be entered into random post while posting to 501-1000 will not be affordable



Version 2

<script type="text/javascript">
semirnd function (root) {
var ttle = root.feed.openSearch $ totalResults. $ t-1;
ttal var = 10;
var random = Math.floor (Math.random () * (ttle-ttal)) +1;
document.write ("<script
}

recentpostslist function (json) {
document.write ("<ul>")
for (var i = 0; i <json.feed.entry.length; i + +)
{
for (var j = 0; j <json.feed.entry [i]. link.length; j + +) {
if (json.feed.entry [i]. link [j]. rel == 'alternate') {
break;
}
}
entryUrl var = "'" + json.feed.entry [i]. link [j]. href + "'";
json.feed.entry entryTitle = var [i]. title. $ t;
var item = "+ <a href="+ entryUrl'" target="_blank"> 'entryTitle + +" </ a> </ li> ";
document.write (item);
}
document.write ('</ ul>');
}
</ Script>

<Script

Description:
- Figure 10 to determine the number of posts that appear at random post.
- Change-tutorial-interesting blog with a blog address that you want.

Excess
Can reach out to all posts in the blog. so even though the blog post on the increase, then all the articles have the opportunity to perform at random post. It is not possible in version 1.

Weakness
Slower than version 1 because the random post to 2 times the request to the RSS feed. The first request to get the total posts, and the second to display the posts.

Up to you to decide, whether fast or precision?
At least this widget will make random loading post is no longer burdensome. If anyone has any other ideas are more efficient, the share is also yes ..... : D
You can run this script directly on TryIt editor, the link is under the posts.



share

No comments:

Post a Comment