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.

 

Need help getting started!

Need help getting started!

Hi,

I am a musician, not a programmer. I really need this module, but can't understand how to get the php code to display a particular module for a category.

Could you please give me an example of the code that would make moudule #138 appear on all pages in category #41.

That could get me started. I am not completely ignorant of php, but I am confused by the recipe. When it says "now customize" I am not sure if I am supposed to be placing that code somewhere else in the script to get it to work, or what. So, if you could give me this specific example I might get it from there.

Thanks very much!

jamieandreas
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: Need help getting started!

Hi jamieandreas,

sorry that the "categories" recipe is one of the longest and most complicated ones on the site. That's going to change in the next few weeks with a new version of MetaMod... but until then we're stuck with it.

The "now customise" bit is actually simpler than you thought. You see the 3 lines below that comment:

if ($category_id == 1) return 55;/* on category 1, return module 55 */
if ($category_id == 2) return 56;/* on category 2, return module 56 */
if ($category_id == 3) return 57;/* on category 3, return module 57 */

Well instead of those 3 lines, just use one of these as a template to do what you need it to do.

e.g.
if ($category_id == 1) return 55;

That means, for category 1, use module 55.

If there are different modules that you want to use for different categories, then just add additional lines just like that one, immediately following that line, just like in the example on the web page.

Obviously, you will need to change the "1" and the "55" to suit your particular site.

Lastly, if you want to return more than 1 module for a particular category, then you need to put the module ids in double quotes like this:

if ($category_id == 1) return "55,56";

Hope that helps - please write back if you need more help with it.

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: Need help getting started!

Oh, by the way here's the complete recipe, including the ID numbers you supplied:

Code:

$category_id = null;

if ( $option == "com_content" ) {
  if ( $view == "category" ) {
   /* category list pages (blog or list style) */
   $category_id = (int)$id;
  } else if (array_key_exists("catid",$_REQUEST)) {
   /* if the category id is in the URL */
   $category_id = (int)JRequest::getInt("catid",0);
  }
  if ( $category_id === null && $view == "article" ) {
   /* if it's an article page without the catid mentioned in the url */
   $nullDate = $db->Quote( $db->getNullDate() );
   $my_id = $db->Quote( $db->getEscaped( (int)$id ) );
   $jnow  =& JFactory::getDate();
   $now    = $db->Quote( $db->getEscaped( $jnow->toMySQL() ) );
   $query = "SELECT  title,  id,  catid "
       . " FROM #__content WHERE id = $my_id AND state = 1"
       . " AND ( publish_up = $nullDate "
       . " OR publish_up <= $now )"
       . " AND ( publish_down = $nullDate "
       . " OR publish_down >= $now  )";
   $db->setQuery( $query, 0, 1 );
   $row = $db->loadObject();
   $category_id = $row->catid;
  }
}
/* Now customise any of the following rules for your use.
* $category_id will correspond to the category id of the
* article being displayed (if one is being displayed!)
*/
if ($category_id == 41) return 138;/* on category 41, return module 138 */

Note: this will display the module on articles that are in category 41 as well as any pages that display category 41 in list or blog view.

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: Need help getting started!

Thanks Steve, that makes it clear.

It also makes it clear that something must be wrong because I still can't get it to work. The thing is, I think I had it working, and modules were showing like their supposed to, and now they don't.

I am trying to think of what other reasons might be the cause of metamod not working for me, now that I know the actual code is correct.

Any ideas?

Jamie

jamieandreas
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: Need help getting started!

Hi Jamie,

a couple of ideas:
1 - the recipe I pasted above assumes that your database prefix is "jos_". Ideally you should change the line above that says "... FROM jos_content " to "... FROM #__content". (that's a # followed by two underscores)

2 - have you read the Quick Start page?  http://www.metamodpro.com/metamod/quick-start

3 - make sure you don't have anything in the datetime boxes, or the "Quick module id include" box in MetaMod. Basically just use a new blank metamod with only the PHP code from above, plus a title, plus any Menu Items selected for the module to appear on.

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

Re: Need help getting started!

By the way, if you install the newest version of MetaMod (2.4c) then you can replace the ENTIRE rule above with this simple line:

if ($content_genius->check("category_id = 41" ) ) return 138;

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: Need help getting started!

Hi Steve,

No matter what I do, I can't get it to work. How about this, how about I give you my login info and you take a look and see if you can get it to work?

If you want to do that, just give me your email and I'll send you the info.


Jamie

jamieandreas
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: Need help getting started!

Hi Jamie,

it's all working now. I just used the recipe:

if ( $content_genius->check("category_id = 41" ) ) return 138;

The only real problem was that you had set the MetaMod to display on "none" pages. You did need to do that for the target module, but not for the MetaMod. The MetaMod has to be set to appear on some pages, otherwise, well, it just wouldn't display.

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

Re: Need help getting started!

That's great Steve, thanks so much! I am glad it was just some dumb little thing like that. I was confused on how that should be configured, so thanks for clearing that up.

I'm off to enjoy my metamod now!

Jamie

jamieandreas
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: Need help getting started!

One more clarification Stephen. When I select a menu in the metamod module, can it be any selection, and then the php code takes effect, or must it be the actual category that corresponds the category chosen in the php code?

Jamie

jamieandreas
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1689
Total Polls:
6
Total Posts:
5941
Total Posts Today:
1
User Info:
 
Total Users:
5328
Newest User:
bwawsc
Members Online:
0
Guests Online:
74

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