Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » Show a module 33% of time?
Show a module 33% of time?
Show a module 33% of time?
How would I show a certain module only 33% of the time. I basically want 3 banner modules to show in the same spot, but they will randomly appear at a 33% rate. I was thinking about basing it on IP or time of day, but that would bias the modules shown. I need a more random way.
Any help is appreciated!
Re: Show a module 33% of time?
how about this. can I use the time features to go by minutes or seconds?
if ($core_genius->inTimeSpan( "**:**:00 - **:**:02") ) return 1;
if ($core_genius->inTimeSpan( "**:**:03 - **:**:05") ) return 2;
if ($core_genius->inTimeSpan( "**:**:06 - **:**:09") ) return 3;
?
I could just load modules randomly based on the second of the load.
Does jomgenius allow variables like that?
Re: Show a module 33% of time?
No, JomGenius doesn't do wildcards in the inTimeSpan method. However if you just want random numbers then do it like this:
$r = mt_rand(1, 3);// random number between 1 and 3
if ($r == 1) return XXX;
if ($r == 2) return YYY;
if ($r == 3) return ZZZ;
// replace XXX-ZZZ with the module number to use in each case.
Cheers,
Stephen
Re: Show a module 33% of time?
answer here:
$now_seconds = date('s');
if (($now_seconds >="00") && ($now_seconds <="19")) return 71;
else if (($now_seconds >="20") && ($now_seconds <="39")) return 228;
else if (($now_seconds >="40") && ($now_seconds <="59")) return 269;
Re: Show a module 33% of time?
Hi - just a quick note about times. What you have above probably works, but it's quite easy to mistakes with time and date calculations, particularly where there are leading zeros.
For the record, I'd do it like this to be on the safe side, without any leading zeros, doing everything as integers instead of strings:
$sec = (int)date("s");
if ($sec < 20) return 71;
if ($sec >= 20 and $sec < 40) return 228;
return 269; // it only gets here if it's not one of the other 2.
Cheers,
Stephen
Re: Show a module 33% of time?
- Index
- » MetaMod
- » MetaMod General Support
- » Show a module 33% of time?
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5942
- Posts this week:
- 2
- User Info:
- Total Users:
- 7627
- Newest User:
- rudys68879
- Members Online:
- 1
- Guests Online:
- 168
- Online:
- rudys68879
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked