Welcome to the MetaMod Support Forums.

Before posting, please check out the FAQs.


greg
Beginner Modder
ranks
useravatar
User Info

First selection random, then in order

I wanted my banner advertisements to be evenly distributed between my advertisers.  I was surprised to find that there were few (if any) banner modules that would randomly select the first module, then proceed through the remainder of the modules in order as visitors reloaded pages or browsed from page to page.

I (very slightly) modified the existing MetaMod recipe for displaying modules in order, to add the facility for randomly selecting the first module in my list.

As with the original, you can insert as many, or as few modules in the array as you need.  I have seven in this example, numbered 119 through 125.

Code:

session_start();

/* set a different "instance name" for each module that you want to show only once */
$instance_name = "module_counter1";
/* use as many or as few as you like, or "0" for no module */
$modules = array(119,120,121,122,123,124,125);
if (!isset($_SESSION[$instance_name]) ||
$_SESSION[$instance_name] == "") {
$_SESSION[$instance_name] = rand(0,(count($modules)));
}


$index = $_SESSION[$instance_name] % count($modules);
$_SESSION[$instance_name]++;
$module_no = $modules[$index];
if ($module_no > 0) return $module_no;


Administrator has disabled public posting
metamodguy
useravatar
User Info

Re: First selection random, then in order

Hey, great modification, thanks! I've seen people asking for things like that on the Joomla forums in the past.

Best regards,
Stephen


Stephen Brandon
MetaMod author
If you use MetaMod or MetaTemplate, please post a rating and a review at the Joomla! Extensions Directory

Administrator has disabled public posting

Board Info

Board Stats:   Total Users: 1159  Total Topics: 411  Total Polls: 1  Total Posts: 1465  Total Posts Today: 10
User Info:   Newest User :  CoPilot   Members Online: 1   Guests Online: 93
Online 
CoPilot
Topic
New
Locked
Topic
New
Locked
Sticky
Active
New/Active
Sticky
Active
New/Active
New/Closed
New Sticky
Closed/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky Active Locked
Active/Sticky
Sticky/Locked
Sticky/Active/Locked