RandomQuote
Questions addressed by this recipe
- How can I implement a "quote of the day"?
- How can I have a rotating image or markup?
- How can I set up a "Did you know" feature similar to MediaWiki?
- How can I create random banners?
Description
The randomsection.phpΔ script makes it possible to insert a random quote from another page into the current one. It does this by defining a {$RandomSection}
page variable, which combined with the (:include:)
markup makes it possible to grab random sections from other wiki pages.
To use this feature, install the randomsection.phpΔ script into the cookbook/ directory, then add an include_once("$FarmD/cookbook/randomsection.php");
line to a local customization file.
Next, create a page containing quotations to be included. Each quotation should be preceded by a unique anchor -- i.e., using the [[#name]]
markup. The Cookbook.Quotes page on this site shows an example set of quotations.
Then, to dynamically insert a random quote from a page, use (:include {PageName$RandomSection}:)
in the markup. For example, to grab a quote at random from the Cookbook.Quotes page, one can do:
Quote of the day: (:include {Quotes$RandomSection}:) |
Quote of the day: Nursie: Oh, that's another good idea. You're so clever today, you better be careful your foot doesn't fall off.
Queenie: Does that happen when you have lots of brilliant ideas? Your foot falls off? Nursie: It certainly does. My brother; he had this brilliant idea of cutting his toenails with a scythe, and his foot fell off... Blackadder
|
Reload this page to see the quotes change.
Note that the quotations can contain arbitrary markup, such as wikistyles, links to other pages or sites, and the like.
The {$RandomSection}
page variable also remembers the section names it has already used, so it can appear multiple times in a page without duplicating quotes.
Comments
Kinda pointing out the obvious but this plugin is also perfect for setting up a "did you know" function, similar to mediawiki's. I set it up for mine and it works like a charm, thanks :D - Com
You can use this feature to display random banners throughout a wiki. Create a banners page and instead of a quotes, put [[<URL> | <URL of the banner picture>]]
. Each banner is seperated by [[#anchors]]
. One can use group headers and/or footers for sitewide banners, or just specific pages with (:include {banners$RandomSection}:)
. Drfredc
Because of some strange quirk in the include make sure the anchor [[#anchor]] is on a separate line to the quote or image.
See Also
- Cookbook.RandomQuote-OldVersion -- previous version of this page
- PmWiki.IncludeOtherPages -- details of the
(:include:)
markup - PmWiki.PageVariables -- details about page variables
- Cookbook:Fortune -- insert a fortune cookie into a wiki page
- Cookbook:RandomPage
Contributors
Sandbox
I changed this script slightly to allow for including only between two specific anchors instead of using only one anchor to delineate. This lets you keep quotes and other content on a nicely formatted page and pull only your anchored contents out (rather than everything between the anchors).
On line 43, change && preg_match_all("/\\[\\[(#$npat)\\]\\]/", $page['text'], $alist)) {
to && preg_match_all("/\\[\\[(#$npat)end\\]\\]/", $page['text'], $alist)) {
That's it! Just add the word 'end' into the anchor format string. I'm not a coder but this solution seems to be working perfectly fine so far. After you've modified the script, simply wrap the sections you want to be pulled in [[#anchor]] ... [[#anchorend]]
tags. --jibegod
Questions
How is this a 'quote of the day' script if there's no option to set the randomness interval? I want a banner to rotate on a daily basis, not on every reload... --jibegod
Quote of the day
Sure there have been injuries and deaths in rugby - but none of them serious.
User notes +3: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.