Show Random Records on Homepage (Glossary entries, etc)

Show Random Records on Homepage (Glossary entries, etc)

by Norberto Bezi -
Number of replies: 1

DESCRIPTION:
This show a random record.

open admin/site.html:
change:
           $options = array("0"  =>  get_string("frontpagenews"),
                            "1"  =>  get_string("frontpagecourselist"),
                            "2"  =>  get_string("frontpagecategorynames"));

with:
           $options = array("0"  =>  get_string("frontpagenews"),
                            "1"  =>  get_string("frontpagecourselist"),
                            "2"  =>  get_string("frontpagecategorynames"),
                            "3"  =>  get_string("frontpagerandomrecord"));

NOTE: If you have more options just use the next number and remenber it

Open course/lib.php:
Change:
define("FRONTPAGENEWS",           0);
define("FRONTPAGECOURSELIST",     1);
define("FRONTPAGECATEGORYNAMES",  2);

With:
define("FRONTPAGENEWS",           0);
define("FRONTPAGECOURSELIST",     1);
define("FRONTPAGECATEGORYNAMES",  2);
define("FRONTPAGERANDOMRECORD",       3);

NOTE: Use the same number you use on the previus step

on your lang moodle.php file:
add:
$string['frontpagerandomrecord'] = 'Show a random record'; 

for spanish lang (es_es):
$string['frontpagerandomrecord'] = 'Mostrar un registro aleatorio';

open index.php:
Go to:
switch ($CFG->frontpage) {     /// Display the main part of the front page.

and add the next case just after the last break; line of the switch:
 case FRONTPAGERANDOMRECORD: /// Show random record
 /// This shoud be a lang string
print_side_block_start("Glossary...");
/// Reading a ramdom glossary record...
 /// This can be done in one line, but this way is clearer to
 /// do changes. You can change the $table value and get random
 /// records from it.
 $table = "glossary_entries";
 $sql = "SELECT * FROM $CFG->prefix$table ORDER BY RAND()";
 if ($glossaryentry = get_record_sql($sql)) {
   /// Here, the fun stuf... printing and formating... I let to you
   /// make this better...
   echo "$glossaryentry->concept<br>$glossaryentry->definition<br>";
 }
print_side_block_end();
break;



INSTRUCTIONS:

Enter Site Configuration in the admin page.

Set home page format to "Show a random record"

Go to the home page. ;)

N.B.

Average of ratings: -
In reply to Norberto Bezi

Re: Show Random Records on Homepage (Glossary entries, etc)

by Norberto Bezi -
Sometimes a think my last two topics must be in other forum, but I don't know in with one must be... sorry if I'm posting in the wrong place ;)