ICT Bersama Sirman

Random posts for blogger/blogspot

salam en.sirman..cikmin nak tanyer la..camner nak buat random post tu…?eh..soklan camni leh tanyer ke…try je la ek…

kasehabadi.blogspot.com

————————————————————————————————-

Sirman said:

dengan menggunakan tahap tertinggi googling skills, sy berjaya menemui an alternative bagaimana nak buat “Random posts for blogger/blogspot

cth leh tgk kat blog sy atas kiri. gerek dak? 8)

senang jer nak buat, just 2 steps jer:

1. Add a Gadget from your Page Elements (cth gbr bwh).

random1

Pilih HTML/JavaScript & paste code bwh ni:

<div id="extract_output">
</div>

1st gadget ni terpulang kat korang nak letak kat mana, so kat mana u letak kat situ la munculnya random posts tu nanti.

2. add the 2nd Gadget from your Page Elements. Tapi kali ni move gadget tu ke bwh sekali. (cth gbr bwh)

random21

pastu paste code ni lak:

UPDATE 4:30pm

seems that code bwh ni dah mess up, tu yg tak jadik tu :[

so please download dr sini:

http://redmummy.com/downloads/ict_bersama_sirman_random_posts.txt

<script type=”text/javascript”>
/*<[CDATA[ <!– */
//Beginning dynamic archive extract code.

//Locate the archive list.
var archive = document.getElementById(“ArchiveList”);
var archive_html = archive.innerHTML;
var links = [];

var introArray = new Array(
“<br>Have you read ^?”,
“<br>Check out ^.”,
“<br>Looking for something to read?  How about ^.”,
“<br>My blog says: \”Look at ^\””,
“<br>I dredged up an old post just for you: ^”,
“<br>Please look at ^.”,
“<br>I wonder if you’d like to read ^?”,
“<br>You might enjoy reading ^.”,
“<br>Look what I found for you: ^”,
“<br>My blog has a post just for you: ^.”
)

//Now search for child elements that have the class “posts”
//These contain the links that we want to extract.

function random_number(range)
{
return (Math.round(Math.random()*200000)%range);
}

var found_place = archive_html.search(‘<‘);

while(found_place!=-1)
{
var extract_string = archive_html.substring(found_place,found_place+10);

//Check to see if we found the beginning of the link section we want.
if(extract_string.localeCompare(“<ul class=”)==0|
extract_string.localeCompare(“<UL class=”)==0)
{
//Found the link list, now go through and extract the links.
var inner_search = archive_html.search(“<“);
if(inner_search==-1)
{
links[links.length]=”(Failed)”;
exit;
}
var loop_flag = true;
while(loop_flag)
{
if(inner_search==-1)
{
exit;
}
else
{
if(archive_html.substring(inner_search,inner_search+5).localeCompare(‘</ul>’)==0|
archive_html.substring(inner_search,inner_search+5).localeCompare(‘</UL>’)==0)
{
//Finished with this archive section so exit.
loop_flag = false;
}
else if(archive_html.substring(inner_search,inner_search+2).localeCompare(‘<a’)==0|
archive_html.substring(inner_search,inner_search+2).localeCompare(‘<A’)==0)
{
//Found a link to extract, now find the end of the link.
var end_link = archive_html.search(“</a>”)+4;
if(end_link==3)  //Returns negative one if fail, so +4 becomes 3.
{
//Must be Internet Exploder, do a capital search.
end_link = archive_html.search(“</A>”)+4;
}
//Do the slice
links[links.length] = archive_html.substring(inner_search,end_link);
}
}
//Cut out opening just found.
archive_html = archive_html.substring(inner_search+1);
//Search again.
inner_search = archive_html.search(‘<‘);
}
}

//Trim out the opening we just found.
archive_html = archive_html.substring(found_place+1);
//Search again.
found_place = archive_html.search(‘<‘);

}

//Great, now we have a list of links from the archive
//Do something with them.

document.getElementById(“extract_output”).innerHTML =”;
var number_of_links = 5;

for(var counter=0; counter<number_of_links; counter++)
{

var output_string = introArray[random_number(introArray.length)];

output_string = output_string.replace(“^”,links[random_number(links.length)]);

//Pick a random link and put it in the output area.
document.getElementById(“extract_output”).innerHTML += output_string;
}

/* ]]> –> */
</script>

pastu save la & jeng jeng jeng dah siap! 🙂

kalo nak customize kan leh gak, cam all those sentences tu kan, boleh la tukar mengikut selera masing2.

“<br>Have you read ^?”,
“<br>Check out ^.”,
“<br>Looking for something to read?  How about ^.”,
“<br>My blog says: \”Look at ^\””,
“<br>I dredged up an old post just for you: ^”,
“<br>Please look at ^.”,
“<br>I wonder if you’d like to read ^?”,
“<br>You might enjoy reading ^.”,
“<br>Look what I found for you: ^”,
“<br>My blog has a post just for you: ^.”

then yg ni plak

var number_of_links = 5;

5 = number of random posts yg korang nak, nak buh 18 pun tak de masalah.

k good luck!

*** credits to Random Post Link Addon Script for Blogger

p/s: kalo utk wordpress lak korang kena install plugins Random Posts from here http://rmarsh.com/plugins/random-posts/

Redmummy said: tidak semua ICT Bersama Sirman is appeared in this blog, most of your questions kalo agak2 biasa je sirman akan jawab to your email directly.

Comment: 24