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.

 

First selection random, then in order

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;

greg
Beginner Modder
ranks
useravatar
Offline
3 Posts
Administrator has disabled public posting

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 / 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: First selection random, then in order

As I understand it, select it first showed module randomly, after they appear in sequence.

But I simply do not understand it to display a modlul only once, I can not get to work!

My code looks like this, and as I understand it will show my module Jumi-Swedish bingo once and then choose randomly and so wise)

But module Jumi-SvenskBingo never arrived?

session_start();
/* set a different "instance name" for each module that you want to show only once */
$instance_name = "Jumi-SvenskBingo";
/* use as many or as few as you like, or "0" for no module */
$modules = array(61,67,68,69,70,71,72,73,74,75,76,77);
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;

Have I misunderstood it as the code be?

stovring
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Re: First selection random, then in order

I'll just state again what the code above does:

- you list a series of module ids that you want to rotate in order
- the first time someone views a page on the site, a random module is chosen from the list
- on the next page they choose, the next module in the list is shown, in order.

This recipe does NOT allow you to choose which module is displayed first.

The "$instance_name" variable does not control which module appears first. It works a bit like a cookie name, and uniquely identifies this particular set of module ids. This is so that you could have more than one of these selectors on the page, and each one would have a different instance_name, and would operate independently from the others.

Here's a variation that allows you to choose a particular module to go first, then use the random feature as above:


/* set the module id for the 1st module to be displayed
*/
$first_module = 51;

/* Now give a list of module ids.
* Use as many or as few as you like, or "0" for no module
* for the modules which appear AFTER the 1st one has been displayed
* The system will choose a random starting point in this list for
* each user.
*/
$modules = array(61,67,68,69,70,71,72,73,74,75,76,77);

/* set a different "instance name" for each set of modules */
$instance_name = "my_modules";

session_start();
if ( !isset( $_SESSION[$instance_name] ) ||
    $_SESSION[$instance_name] == "") {
  $_SESSION[$instance_name] = rand(0,(count($modules)));
  return $first_module;
}
$index = $_SESSION[$instance_name] % count($modules);
$_SESSION[$instance_name]++;
$module_no = $modules[$index];
if ($module_no > 0) return $module_no;


Hope that helps,
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: First selection random, then in order

Hello! I've bought several modules but never seen a support that work so well as here! - I have not written many posts, but the few I've written has always been answered quickly and with very competent answers.

I try just the above code, on Sunday when I get home!

Many thanks! From Denmark!

Google Translate is my friend!

stovring
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Re: First selection random, then in order

It works just fantastic! - But then I do like to have more .. is it possible that when metamod have chosen the first banner, and displayed it to the next banner in the list shown after eg 15 seconds and so on - without page reloads.
- Select banner1 - wait 15 seconds and if the page is reloaded traffics - show banner2 - wait 15 seconds and if the page is reloaded traffics - show banner3 ................

(google translate)

stovring
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Re: First selection random, then in order

Hi stovring,

doing modules changes without page reloads is a COMPLETELY different situation to normal. MetaMod can't help you with that, sorry. There are some modules around that can rotate banners or images, but I don't know of any that can rotate modules. This may exist though - have a look on the JED and see what you can find.

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

Board Info

Board Stats:
 
Total Topics:
1680
Total Polls:
6
Total Posts:
5914
Total Posts Today:
1
User Info:
 
Total Users:
10831
Newest User:
bluesky1
Members Online:
0
Guests Online:
172

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