Personal Development for Smart People Forums

Personal Development for Smart PeopleTM Forums

 

Go Back   Personal Development for Smart People Forums > Personal Development > Technology & Technical Skills

Technology & Technical Skills Computer skills, hardware, software, internet topics, gadgets, programming


Welcome to the Personal Development for Smart People Forums, the place for lively, intelligent discussion of all personal growth issues -- physical, mental, financial, social, emotional, spiritual, and more.

You're currently viewing as a guest, which gives you limited read-only access. By joining our free community, you'll be able to post your own messages, access many members-only features, see the new messages posted since your last visit, and of course remove this header message. Registration is fast, simple, and free, so please join today.

If you arrived here from a search engine, you may want to explore the main site first, which includes hundreds of deep and insightful articles on a variety of personal development topics.
Reply
 
Thread Tools Display Modes
Old 03-20-2009, 05:37 PM   #1 (permalink)
Senior Member
 
Join Date: Oct 2007
Posts: 341
Ralph is on a distinguished road
Default Random Quote - please help me implement such function

I'd love to use random inspirational quotes in the header of my Wordpress blog. However, I need some assistance with the technical side.

Could you please share with me or direct me to the script that will work? Please give me directions as to how to input such script to the html file to make it work. It'll replace the foreign words in the header of my blog.

I'm deeply grateful for every bit of help

Ralph
__________________
Ralphdudek.com - Consciously Pursuing Your Heart's Desire

Extreme caution advised! Entering may result in intense growth!
Ralph is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-21-2009, 03:53 AM   #2 (permalink)
Senior Member
 
Join Date: Oct 2008
Location: Cleveland, OH
Posts: 537
runningbird is on a distinguished road
Default

I can tell you how to do it in javascript - very easy.

Start by declaring an array; each quote will be one element in the array. So you have:

var quotes = new Array(11);
quote[0] = "You are what you eat";
quote[1] = "Government is a lousy master and a treacherous servant";
quote[2] = "For the first time in history, it is possible to meet the needs for 100% of the global population";
etc.

So if you have 11 quotes your last one will be quote[10];

Then, to choose a random number of the array make a random number generator:

var choice = Math.floor(Math.random()*11);

Math.floor is to get an integer number. ^That 11 is because I assume 11 quotes; adjust it to your number. (Math.random() gives you a random decimal between 0 and 1)

Then just write it.

document.write(quotes[choice]);

Write that in text editor and save as something like quote_gen.js

Then upload the file onto your sever. Where you want it to appear, insert the script:

<script src="quote_gen.js" type="text/javascript"></script>
runningbird is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-23-2009, 05:24 AM   #3 (permalink)
Senior Member
 
Join Date: Oct 2007
Posts: 341
Ralph is on a distinguished road
Default

Thanks a lot runningbird.

I followed your directions and unfortunately it didn't work. Luckily, I managed to find a script that worked out for me. I did nothing but paste this in the place it appeared:

Code:
<script type="text/javascript">
// <![CDATA[
Array.prototype.random = function(limit)
{
	if (typeof limit == 'undefined' || limit < 0) limit = 1;
	else if (!limit) limit = this.length;
	for (var i = 0, source = this, target = new Array(), n = source.length; i < limit && n > 0; i++)
	{
		do { var index = Math.random(); } while (index == 1);
		index = Math.floor(index * n);
		target.push(source[index]);
		source[index] = source[--n];
	}
	return target;
}

document.write(new Array(
// Enter the elements here:

'Tekst 1',
'Tekst 2',
'Tekst 3'

).random().join(''));
// ]]>
</script>

I opt for one more tweak. Perhaps you could help me out. Therre are two paragraphs in the place for my quotes. The difference between them is style (class="para1" and class="para2"):

<p class="para1">Quisque sed felis. </p>

<p class="para2">Quisque sed felis. </p>


I pasted my script inside the <p class="para1"> </p> and it worked out well. I would like to place the quote author in <p class="para2"> </p>. I can't do that by placing the same script because the author would be chosen randomly, instead of according to the chosen quote. So there are two ways in which you could help me out:

1. Verify the script code and make it write two paragraphs with style defined instead of just plain text

2. Create a javascript that uses the same variable as the first one in choosing between the texts. This way, if the quote 2 would be chosen in the first script, the second script would automatically choose author 2. I could make the list of authors corresponding to the list of quotes.




Thanks a lot and looking forward to hearing from you again


UPDATE: Help! This script works only for 3 quotes. When I add fourth one, nothing shows up. Where can I change the max. number of quotes? Please help

Ralph
__________________
Ralphdudek.com - Consciously Pursuing Your Heart's Desire

Extreme caution advised! Entering may result in intense growth!

Last edited by Ralph; 03-23-2009 at 10:04 PM.
Ralph is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-24-2009, 02:59 PM   #4 (permalink)
Senior Member
 
Join Date: Oct 2008
Location: Cleveland, OH
Posts: 537
runningbird is on a distinguished road
Default

Unfortunately, I cannot really make sense of that script. Sorry mine didn't work out. I am not that adept in javascript, but I had made a random sentence generator when I was trying to learn it. Hopefully someone else can help you out.
runningbird is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Random quote Parthon Social & Relationships 7 01-13-2009 08:14 AM
What if everyone was living their purpose? Could the world still function? cpalmer Character & Contribution 28 01-01-2009 02:41 AM
Who effectively managed to implement GTD? Dolazy Personal Effectiveness 18 08-26-2007 02:40 AM
[Random] Yohojo's Sleeping Schedule [Random] Yohojo Health & Fitness 1 02-06-2007 05:46 AM
Function pointers instead of dlls in C++ Minsc Technology & Technical Skills 1 11-07-2006 09:01 AM


All times are GMT. The time now is 04:49 AM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 by Pavlina LLC