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 module in specific categories

random module in specific categories

hi,

can you please tell me how to combine the random module recipe with a category page exclusion recipe? i want to be able to randomize 3 modules in metamod, but i don't want them to appear on every page. i would like to control which pages they appear on.

this is the random recipe with the modules i want to 'return' and/or include on certain pages:

$r = mt_rand(1,3); // get a random number: 1-3 inclusive
if ($r == 1) return 118;
if ($r == 2) return 116;
if ($r == 3) return 125;

this is the exclusion code:

if ( $content_genius->check("category_id not = any of 65,66,67") ) return "118, 116, 125";

but no matter how i string them together, the modules either appear in a row (together, not randomized, all atop each other in right position) on the pages i want....or they appear on 'excluded' pages (working and randomized, but still displayed on pages i hope to exclude).

seems to be one or the other.

is there any way to specify which categories get the random module code and which don't? or any other means of configuring the same outcome?

please advise.

thank you.

Edited By: baituo01
14-Oct-11 22:34:20

baituo01
Intermediate Modder
ranks
useravatar
Offline
46 Posts
Administrator has disabled public posting

Re: random module in specific categories

Hi baituo01,

First of all a quick note: if you want to check if a number does NOT appear in a list, then you should do it this way:

if ( $content_genius->check("category_id = none of 65,66,67") ) return "118, 116, 125";

(if you use "not = any of" then that means "not = 65, or not = 66, or not = 67", so it will always return true. "none of" is better because it means "not = 65 AND not = 66 AND not = 67").

Anyway, in your case I think you're trying to say "I don't want anything on category pages 65, 66 or 67, and I want a single random item on any other page". Correct?

So I'd do it this way:

// return nothing (no module) for these categories:
if ( $content_genius->check("category_id = any of 65,66,67") ) return;
// so if we get to here, then we're obviously not in one
// of those categories, so return a random module:
$r = mt_rand(1,3); // get a random number: 1-3 inclusive
if ($r == 1) return 118;
if ($r == 2) return 116;
if ($r == 3) return 125;


Now, if you meant that you only want the random modules on those 3 pages, and nothing on any other pages, then you could do this:

// bypass any page that's not in cat 65, 66, 67:
if ( $content_genius->check("category_id = none of 65,66,67") ) return;
$r = mt_rand(1,3); // get a random number: 1-3 inclusive
if ($r == 1) return 118;
if ($r == 2) return 116;
if ($r == 3) return 125;


Did I get the right combination for you? I'm not 100% sure which version you intended, or maybe I didn't get it right at all... sorry.

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

Re: random module in specific categories

the second recipe is what i intended. thank you very much.

baituo01
Intermediate Modder
ranks
useravatar
Offline
46 Posts
Administrator has disabled public posting

Re: random module in specific categories

hi, stephen.

sorry to bother you with this again. i thought that last recipe would work in my situation but it doesn't seem to and i haven't been able to try until now.

basically what i want to do is pretty simple.

i have three advertisements. (module id: 125, 116, 118) i want to be able to display them randomly on selected pages (category id: 68, 51, 57). other modules appear on other pages, but i do not want these 3 advertisements to display on other pages.  the advertisements should only appear in the categories listed above.

what i currently have in metamod:

if ($content_genius->check("category_id = 68")) return "27, 93, 83, 116, 112";

if ($content_genius->check("category_id = 51")) return "27, 93, 83, 118, 112";

if ($content_genius->check("category_id = 57")) return "27, 93, 83, 125, 112";

(displays modules correctly on selected pages (namely 68,51,57))

// bypass any page that's not in cat 68, 51, 57:
if ( $content_genius->check("category_id = none of 68,51,57") ) return;
$r = mt_rand(1,3); // get a random number: 1-3 inclusive
if ($r == 1) return 118;
if ($r == 2) return 116;
if ($r == 3) return 125;

(does not work to display advertisements (118,116,125) on same pages (namely 68,51,57))

please advise.

thank you.

baituo01
Intermediate Modder
ranks
useravatar
Offline
46 Posts
Administrator has disabled public posting

Re: random module in specific categories

Hi,

Are you saying that you want those first lists of advertisements to appear in their respective categories, and then ADDITIONALLY you want one of the random modules to appear?

If so, try it this way:

Code:

// bypass any page that's not in cat 68, 51, 57:

if ( $content_genius->check("category_id = none of 68,51,57") ) return;
$mods = "";
if ($content_genius->check("category_id = 68")) $mods = "27, 93, 83, 116, 112";
if ($content_genius->check("category_id = 51")) $mods = "27, 93, 83, 118, 112";
if ($content_genius->check("category_id = 57")) $mods = "27, 93, 83, 125, 112";

$r = mt_rand(1,3); // get a random number: 1-3 inclusive
if ($r == 1) $mods .= ",118";
if ($r == 2) $mods .= ",116";
if ($r == 3) $mods .= ",125";
return $mods;

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:
1696
Total Polls:
6
Total Posts:
5941
Posts this week:
7
User Info:
 
Total Users:
5418
Newest User:
outsd2
Members Online:
0
Guests Online:
153

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