Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » random module in specific categories
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.
14-Oct-11 21:34:20
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
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.
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;
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » random module in specific categories
Board Info
- Board Stats:
- Total Topics:
- 1699
- Total Polls:
- 6
- Total Posts:
- 5967
- Total Posts Today:
- 2
- User Info:
- Total Users:
- 8027
- Newest User:
- henley7346
- Members Online:
- 1
- Guests Online:
- 195
- Online:
- henley7346
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked