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.

 

Display Random Module When Another Is Absent

Display Random Module When Another Is Absent

This recipe combines the "Show a module on every page that another module does not appear" and "Select modules randomly" to give you double the pleasure.

Code:

$r = mt_rand(1,6); // get a random number: 1-6 inclusive

$moduleid = 63; /* the module we are checking for. Customise this! */
$sql = 'SELECT count(*) as c from #__modules m, #__modules_menu mm ' .
  'WHERE mm.moduleid = m.id ' .
  'and m.published = 1 ' .
  'and (mm.menuid = ' .
  (int)$Itemid . ' or mm.menuid = 0) and mm.moduleid = ' . (int)$moduleid;

$db->setQuery( $sql, 0, 1 );
$row = $db->loadObject();

$not_there = ($row == null or $row->c == 0);

if ($not_there and $r == 1) return 45;
if ($not_there and $r == 2) return 61;
if ($not_there and $r == 3) return 64;
if ($not_there and $r == 4) return 65;
if ($not_there and $r == 5) return 66;
if ($not_there and $r == 6) return 67;

I'm sure there's a more elegant way to write the code but this worked for me.

It would be nice if someone could help me out with my recipe request in the forum.

Enjoy

fettabachi
Beginner Modder
ranks
useravatar
Offline
7 Posts
Administrator has disabled public posting

Re: Display Random Module When Another Is Absent

Nice! Thank you.

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
3329 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1685
Total Polls:
6
Total Posts:
5940
Total Posts Today:
1
User Info:
 
Total Users:
5186
Newest User:
Totosite
Members Online:
0
Guests Online:
164

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