Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Random Modules

Random Modules

So I have a couple of modules that are based on mod_rquotes that I want to randomly display at a site. One module is titled "Leave No Trace" that we randomly have the "Leave No Trace" principles displayed and the other is "The Ten Essentials" that we randomly have the essential things to take with you when you are hiking. Right now I have mod_rquotes set up to randomly display each 'quote' at each page request. So what I would like to do is randomly have the "Leave No Trace" module and "The Ten Essentials" module appear at each page request. Hope that made sense. My guess is that there is probably some kind of PHP trick that I would use to do that but it escapes me.

sackerman
Beginner Modder
ranks
useravatar
Offline
6 Posts
Administrator has disabled public posting

Re: Random Modules

Hi Sackerman,

there's a recipe for doing random selection: http://www.metamodpro.com/support/recip … s-randomly

If it's a 50-50 split between the 2 modules, then I'd do the following:

if ( rand( 1,2 ) == 1 ) return 101;
else return 102;

(replace 101 and 102 with the module numbers of the modules you want to randomly display).

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Random Modules

Thanks! I thought that I had looked at the recipes but apparently not (RTFM I guess ;-) Now to really add some icing on the cake, is there a way of pulling the different module class suffixes for each one so that the styles vary based on the included module?

sackerman
Beginner Modder
ranks
useravatar
Offline
6 Posts
Administrator has disabled public posting

Re: Random Modules

See http://www.metamodpro.com/support/contr … parameters

After you've decided which module to include, use syntax something like:

$changes->mod(101)->setParam('moduleclass_sfx','-mysuffix');
return 101;


So overall the rule might be:

if ( rand( 1,2 ) == 1 ) {
  $changes->mod(101)->setParam('moduleclass_sfx','-mysuffix');
  return 101;
}
else {
  $changes->mod(102)->setParam('moduleclass_sfx','-mysuffix2');
  return 102;
}

This assumes PHP5. If youare using PHP4 this will either not work or give an error... let me know if that's the case and I'll try to remember how to do it in PHP4.

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5914
Total Posts Today:
1
User Info:
 
Total Users:
10814
Newest User:
lloyd56785
Members Online:
0
Guests Online:
182

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked