Random quotes - how to get them working! // Zufalls-Zitat

Discuss phpwcms here, please do not post support requests, bug reports, or feature requests! Non-phpwcms questions, discussion goes in General Chat!
Post Reply
User avatar
oeconom
Posts: 337
Joined: Fri 13. May 2005, 09:33
Location: Stuttgart
Contact:

Random quotes - how to get them working! // Zufalls-Zitat

Post by oeconom »

Hey folks,
finally found a script to realize random quotes easily, even on your site!
This script will show one quote per day.

How to:

1. First, create a *.js File calles "quote.js", containing the following code:

Code: Select all

now = new Date
Day = new Array
//Edit the Quotes below
Day[1] = "Quote Day 1"
Day[2] = "Quote Day 2"
Day[3] = "Quote Day 3"
Day[4] = "Quote Day 4."
Day[5] = "Quote Day 5"
Day[6] = "Quote Day 6"
Day[7] = "Quote Day 7"
Day[8] = "Quote Day 8"
Day[9] = "Quote Day 9"
Day[10] = "Quote Day 10"
Day[11] = "Quote Day 11"
Day[12] = "Quote Day 12"
Day[13] = "Quote Day 13"
Day[14] = "Quote Day 14"
Day[15] = "Quote Day 15"
Day[16] = "Quote Day 16"
Day[17] = "Quote Day 17"
Day[18] = "Quote Day 18"
Day[19] = "Quote Day 19"
Day[20] = "Quote Day 20"
Day[21] = "Quote Day 21"
Day[22] = "Quote Day 22"
Day[23] = "Quote Day 23"
Day[24] = "Quote Day 24"
Day[25] = "Quote Day 25"
Day[26] = "Quote Day 26"
Day[27] = "Quote Day 27"
Day[28] = "Quote Day 28"
Day[29] = "Quote Day 29"
Day[30] = "Quote Day 30"
Day[31] = "Quote Day 31"

document.write("<Font color=#000000>")
document.write("<Font size=2>")
document.write("<center><i>"" + Day[now.getDate()] + ""</i></center>")
document.write("</Font>")
document.write("</Font>")
2. Secondly, upload the *.js file into your phpwcms base directory

3. Finally, insert this tag into a content part or your template (as you wish) an it will be shown on your site:

Code: Select all

<script src="quote.js"></script>

Simple, isn't it?!?


I'd appreciate if someone aould modify the script to show a new quote on every reload, or a shorter time than daily. As you indubitably see, I'm not to confident wirh coding... :wink:

Many greetings,
FELIX
...alles wird gut!
still alive...
Experimenting with phpwcms and hoping to have time one day to get a site live... :wink:
One Site finished! :P
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

Why use javascript when php does it better

see this link from google
http://www.google.co.za/search?q=php+ra ... S:official

or a script in action
http://www.chipmunk-scripts.com/randomq ... mquote.php

enjoy
TriP
User avatar
oeconom
Posts: 337
Joined: Fri 13. May 2005, 09:33
Location: Stuttgart
Contact:

Post by oeconom »

trip,
new and better suggestions are always warmly welcome to me!!
I only didn't find here in the phpwcms forum any solution to this frequently asked request for realizing random quotes.

Great, so let's start a collection of possible options here.

Greetings,
FELIX
...alles wird gut!
still alive...
Experimenting with phpwcms and hoping to have time one day to get a site live... :wink:
One Site finished! :P
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

okay here is an example of php quotes

create this file and use the [PHP] file from phpWCMS to include it

FILE: quotes1.inc

Code: Select all

<?
$quote = file("quotes.txt");
srand((double)microtime()*1000000);
echo $quote[rand(0,count($quote))];
?>
create this file called
FILE: quotes.txt
add all your quotes into this file
one per line

Code: Select all

When you feel terrific, notify your face.
Worry pulls tomorrow's cloud over today's bright sunshine.
One today is worth two tomorrows.
remember you can also change the location of the inc file and the txt file, you need to use _SERVER["DOCUMENT_ROOT"] to make an explicite location...

hope this helps...
TriP
User avatar
oeconom
Posts: 337
Joined: Fri 13. May 2005, 09:33
Location: Stuttgart
Contact:

Post by oeconom »

Great trip, thank you!

Does anyone know a way to fomat those quotes differently, e.g. quote text normal black aligned left, name of the person who said it in light grey italc and aligned right.

Felix
...alles wird gut!
still alive...
Experimenting with phpwcms and hoping to have time one day to get a site live... :wink:
One Site finished! :P
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

use css in your text file...

format the span tag using css and then you should be okay
ie align left bold, italics etc

trip

Code: Select all


<span>this is a quote</span>

happy
Posts: 5
Joined: Wed 8. Jun 2005, 05:19

You lost me!

Post by happy »

Great I like this idea. I don't know php so please help me.
I created both files quotes1.inc and quotes.txt, but this I don't understand.
okay here is an example of php quotes

create this file and use the [PHP] file from phpWCMS to include it
olleolleolle
Posts: 24
Joined: Mon 18. Apr 2005, 21:35
Location: Copenhagen, Denmark
Contact:

Is that a PHP file content-part?

Post by olleolleolle »

"PHP variables", is that the one?
Olle Jonsson
olleolleolle
olleolleolle
Posts: 24
Joined: Mon 18. Apr 2005, 21:35
Location: Copenhagen, Denmark
Contact:

HOWTO include PHP files in templates

Post by olleolleolle »

1. create a script and put it in a folder, let's say /scripts/ (You need to make that folder if it does not exist yet.)

Name your file quotes1.php

2. In your Template or HTML Content Part you can then go:

Code: Select all

{PHP:scripts/quotes1.php}
Olle Jonsson
olleolleolle
Post Reply