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.

 

Problem Metamod & Categories

Problem Metamod & Categories

I want modules displayed based on categories and have followed instructions as per recipe, this is the PHP that I've used:

$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 == 70) return 327;
if ($category_id == 17) return 287;
if ($category_id == 26) return 279;
return 3; /* default if nothing else matches */

It just does not want to display, I do have another metamod module in that position to display on all pages and that is displaying fine.
I have not used the “Quick module position or id include” box.
Any suggestions?
Thanks.

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

Re: Problem Metamod & Categories

Hi LTJ,

have you turned on MetaMod Debug mode to see if that gives any clues? This should give some output on every front-end page on which the MetaMod is assigned. So, if you don't see any debug output, then either the MetaMod isn't enabled, or is not published to any pages. Once you see some output, then hopefully that will let you know why it isn't including any modules.

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

Re: Problem Metamod & Categories

Hi Stephen,

This is the output which doesn't give me any clues:

$option == 'com_content'
and $view == 'article'
and $id == '1306'
and JRequest::getVar('catid') == '3'
and JRequest::getVar('url') == NULL /*!*/
and JRequest::getVar('layout') == 'default' /*!*/
and JRequest::getVar('lang') == 'en'
) return XXX; /* replace XXX with the module ID or position to display */

MetaMod debug info:
$option: com_content
$view: article
$id: 1306
$Itemid: 0
$timezone: default
$language: en-us
$language_code: en
$language_region: us
Including modules: 3

Well at least I know the module is published, any ideas?

Thanks

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

Re: Problem Metamod & Categories

well, it says that it's including module id 3. So can you check that you have a module with id 3, and that it's really the one that you want? To test, try returning a different module ID from your PHP code, taken from the list of modules that appears above the PHP box. Do any of the others appear correctly?

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

Re: Problem Metamod & Categories

OK, I changed this portion of the PHP code:

if ($category_id == 70) return 327;
if ($category_id == 17) return 287;
return 278; /* default if nothing else matches */

And now the module "278" is displaying, but on every page of the site. Perhaps I'm not understanding correctly, I want module "327" to display only on pages with the category id "70", and module"287" to display only on pages with the category id "17", and the module "278" should only display if these other modules don't match, is this correct?

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

Re: Problem Metamod & Categories

This works perfectly on my local server, but cannot get it working on the live site.

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

Re: Problem Metamod & Categories

Hi LTJ,

- are the category ids the same on the local server and live site?
- what are you seeing happen? Is it always just showing the default module?

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

Re: Problem Metamod & Categories

Hi Stephen,

No, the local server has different content, modules and components although it is the same template.
On the local server I used 0 as the default module and it worked perfectly.
I tried this on the site and got this in the debug output:

if (
$option == 'com_content'
and $view == 'article'
and $id == '1321'
and JRequest::getVar('catid') == '3'
and JRequest::getVar('url') == NULL /*!*/
and JRequest::getVar('layout') == 'default' /*!*/
and JRequest::getVar('lang') == 'en'
) return XXX; /* replace XXX with the module ID or position to display */

MetaMod debug info:
$option: com_content
$view: article
$id: 1321
$Itemid: 0
$timezone: default
$language: en-us
$language_code: en
$language_region: us
Ignoring module position "right". A MetaMod cannot include the same module position that it is in.
Including modules:

This is weird as I don't have a category id 3 in the PHP code and neither am I using a right module position.

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

Re: Problem Metamod & Categories

Hi LTJ,

The Advanced Debug Mode is simply picking up parameters from the URL and creating a sort of rule that would use all of these parameters.

The output above tells me that the article you are viewing is in category 3, and is a standard article. That's all good.

The note about "right" says that somewhere in the rule in the PHP box (that you typed in), OR in the Quick Module ID Include box, you have the word "right". Generally, if you are using a PHP rule then you should not use the Quick Module ID Include box. I suspect you have the word "right" in there. Correct? Just remove it.

So, for the article that's being displayed as per your last test on the live server, which module did you want to display? The article is in category 3, so should the default module 278 be displayed? Or one of the other ones?

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

Re: Problem Metamod & Categories

Hi Stephen,

The problem is that I did not use category 3 in the PHP code.

I have not included anything in the QuickModule ID.

These are the two PHP variations I have used:

if ($category_id == 30) return 291;
return 327; /* default if nothing else matches */

This shows module 327 on every page on the site.

Debug:
if (
$option == 'com_content'
and $view == 'article'
and $id == '1394'
and JRequest::getVar('catid') == '3'
and JRequest::getVar('url') == NULL /*!*/
and JRequest::getVar('layout') == 'default' /*!*/
and JRequest::getVar('lang') == 'en'
) return XXX; /* replace XXX with the module ID or position to display */

MetaMod debug info:
$option: com_content
$view: article
$id: 1394
$Itemid: 0
$timezone: default
$language: en-us
$language_code: en
$language_region: us
Including modules: 327

I then tried this code which worked perfectly on my local server:

if ($category_id == 30) return 291;
return 0; /* default if nothing else matches */

Nothing displays on any category.

Debug:

if (
$option == 'com_content'
and $view == 'article'
and $id == '1321'
and JRequest::getVar('catid') == '3'
and JRequest::getVar('url') == NULL /*!*/
and JRequest::getVar('layout') == 'default' /*!*/
and JRequest::getVar('lang') == 'en'
) return XXX; /* replace XXX with the module ID or position to display */

MetaMod debug info:
$option: com_content
$view: article
$id: 1321
$Itemid: 0
$timezone: default
$language: en-us
$language_code: en
$language_region: us
Ignoring module position "right". A MetaMod cannot include the same module position that it is in.
Including modules:

I'm beginning to think there is a conflict with another component, is this possible?

Thanks for the support.

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

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5933
Posts this week:
4
User Info:
 
Total Users:
4383
Newest User:
kingpen99
Members Online:
0
Guests Online:
189

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