Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-01-2017, 06:30 PM
Alice Alice is offline
 
Join Date: Mar 2013
Location: Great Lakes Area
Posts: 81
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default vBulletin 3 Request - Random Quotes

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:

Code:
<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,
Reply With Quote
  #2  
Old 04-01-2017, 06:44 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 04-01-2017, 06:48 PM
Alice Alice is offline
 
Join Date: Mar 2013
Location: Great Lakes Area
Posts: 81
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarkFL View Post
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?
Reply With Quote
  #4  
Old 04-01-2017, 06:52 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 04-01-2017, 06:53 PM
Alice Alice is offline
 
Join Date: Mar 2013
Location: Great Lakes Area
Posts: 81
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So you can use the plugin in much the same way as I did to define the $quotemain for the footer template, right?

Code:
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 [DATE]1491083304[/DATE] at [TIME]1491083304[/TIME] ---------------

Quote:
Originally Posted by MarkFL View Post
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 &quotemain), I added:

Code:
<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:

PHP Code:
    <!-- 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
      
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:

PHP Code:
      <!-- 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
Reply With Quote
  #6  
Old 04-01-2017, 08:02 PM
blind-eddie's Avatar
blind-eddie blind-eddie is offline
 
Join Date: Apr 2006
Location: Michigan
Posts: 2,310
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Use this.... edit to your liking
I have an edited version of it on my site.

https://vborg.vbsupport.ru/showthrea...highlight=tips
Reply With Quote
  #7  
Old 04-02-2017, 12:44 AM
Alice Alice is offline
 
Join Date: Mar 2013
Location: Great Lakes Area
Posts: 81
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by blind-eddie View Post
Use this.... edit to your liking
I have an edited version of it on my site.

https://vborg.vbsupport.ru/showthrea...highlight=tips
Thank you so much for your contribution. I've actually already implemented what I included above and it works splendidly
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 09:40 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04022 seconds
  • Memory Usage 2,244KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (2)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete