Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod Favourite Recipes
- » Display Random Module When Another Is...
Page:
1
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
Administrator has disabled public posting
Page:
1
- Index
- » MetaMod
- » MetaMod Favourite Recipes
- » Display Random Module When Another Is...
Board Info
- Board Stats:
- Total Topics:
- 1700
- Total Polls:
- 6
- Total Posts:
- 5967
- Total Posts Today:
- 1
- User Info:
- Total Users:
- 8052
- Newest User:
- maarie443
- Members Online:
- 0
- Guests Online:
- 209
- 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