View Full Version : vBulletin 3 Request - Random Quotes
Alice
04-01-2017, 06:30 PM
Hello Again,
Does anyone happen to know the best method to have random quotes displayed everytime a page in vBulletin is refreshed?
An image of where I have setup for the quotes to be displayed is as follows:
http://i.imgur.com/29KA8Fk.png?1
And the code for that is:
<table class="tcat" cellpadding="4" cellspacing="0" border="0" width="100%" align="center" style="border-top:1px solid $stylevar[tborder_bgcolor]; border-bottom:1px solid $stylevar[tborder_bgcolor]">
<tr>
<td height="1" bgcolor="$stylevar[tcat_bgcolor]">
</td>
<tr>
<td align="center" bgcolor="$stylevar[select_bgcolor]">
<font face="verdana,arial,helvetica" size="1" ><i>"Quote Text."</i> - <b>Quote Author</font>
</td>
<tr>
<td height="1" bgcolor="$stylevar[tcat_bgcolor]">
</td>
</table></table>
</div>
Hopefully, someone out there is able to provide some insight. Thank you,
MarkFL
04-01-2017, 06:44 PM
What I would do is define a 2D array of quotes, where each element of the array contains a quote and the author, and then generate a random number between 1 and the length of the array (inclusive), then pass the selected array element to your template. :)
Alice
04-01-2017, 06:48 PM
What I would do is define a 2D array of quotes, where each element of the array contains a quote and the author, and then generate a random number between 1 and the length of the array (inclusive), then pass the selected array element to your template. :)
How would I interface that with a vbulletin template though? Like there are plenty of random tutorials out there that involve php code, but I don't know how to integrate that into a vBulletin template so its a little confusing, you know?
MarkFL
04-01-2017, 06:52 PM
You could use a global plugin hook, and I believe in vB 3 you don't even need to register the variables in your template.
I don't have time right now, but if you want, I will look into creating a vB 3.8.x product to do this. :)
Alice
04-01-2017, 06:53 PM
So you can use the plugin in much the same way as I did to define the $quotemain for the footer template, right?
eval('$quotemain= "' . fetch_template('quotes_main') . '";');
eval('$quotetext= "' . fetch_template('quotes_text') . '";');
It might be a good idea. I know so many people still use 3.8.x, heck I still know someone who still uses 2.3.x LOL!
--------------- Added 1491083304 at 1491083304 ---------------
You could use a global plugin hook, and I believe in vB 3 you don't even need to register the variables in your template.
I don't have time right now, but if you want, I will look into creating a vB 3.8.x product to do this. :)
Okay, so I got somewhere with this. In the quotes_main template (which is called in the footer template as "emain), I added:
<script type="text/javascript" src="clientscript/quotes_database.js"></script>
<script type="text/javascript" src="clientscript/quotes_call.js"></script>
The contents of the quotes_database.js is:
<!-- Hide the script from old browsers
function getQuote() {
// Create the arrays
quotes = new Array(4);
sources = new Array(4);
// Initialize the arrays with quotes
quotes[0] = "When I was a boy of 14, my father was so ignorant..." +
"but when I got to be 21, I was astonished at how much he had learned " +
"in 7 years.";
sources[0] = "Mark Twain";
quotes[1] = "Everybody is ignorant. Only on different subjects.";
sources[1] = "Will Rogers";
quotes[2] = "They say such nice things about people at their funerals " +
"that it makes me sad that I'm going to miss mine by just a few days.";
sources[2] = "Garrison Keilor";
quotes[3] = "What's another word for thesaurus?";
sources[3] = "Steven Wright";
// Get a random index into the arrays
i = Math.floor(Math.random() * quotes.length);
// Write out the quote as HTML
document.write("<dl style='background-color:#F7D7C8'>\n");
document.write("<dt>" + "\"<i>" + quotes[i] + "</i>\"\n");
document.write("<b><dd>" + "- " + sources[i] + "</b>\"\n");
document.write("<dl>\n");
}
// Stop hiding the script -->
And the contents of quotes_call.js is:
<!-- Hide the script from old browsers
getQuote();
// Stop hiding the script -->
And this is how it shows up on my forum:
http://i.imgur.com/WKaQou4.png?1
-Sara
blind-eddie
04-01-2017, 08:02 PM
Use this.... edit to your liking
I have an edited version of it on my site.
https://vborg.vbsupport.ru/showthread.php?t=170032&highlight=tips
Alice
04-02-2017, 12:44 AM
Use this.... edit to your liking
I have an edited version of it on my site.
https://vborg.vbsupport.ru/showthread.php?t=170032&highlight=tips
Thank you so much for your contribution. I've actually already implemented what I included above and it works splendidly :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.