Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.


pview
Beginner Modder
ranks
useravatar
User Info

Display modules based on Category, also a default if other

Here is the current code that I am using, I grabbed this somewhere on this forum and made a small addition for the com_sefservicemap

// IMPROVED VERSION FOR JOOMLA 1.5, SPECIFICALLY FOR GETTING CATEGORIES
// INCLUDING BLOG OR LIST STYLE CATEGORY PAGES
///////////////////////////////////
if ($option == "com_content" && $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)$_REQUEST["catid"];
} else if ($option == "com_content" && $view == "article") {
   /* if it's an article page without the catid mentioned in the url */
   $nullDate = $db->Quote($db->getNullDate());
   $my_id = $db->getEscaped((int)$id);
   $query = "SELECT  title,  id,  catid,  sectionid"
      . " FROM #__content WHERE id = '$my_id' AND state = 1"
      . " AND ( publish_up = " .  $nullDate
      . " OR publish_up <= CURRENT_TIMESTAMP )"
      . " AND ( publish_down = " . $nullDate
      . " OR publish_down >= CURRENT_TIMESTAMP  )";
   $db->setQuery( $query, 0, 1 );
   $row = $db->loadObject();
   $category_id = $row->catid;
   $section_id = $row->sectionid;
}elseif ($option == "com_sefservicemap") {
return 47;
} else {
return 47;
}


if ($category_id == 34) return 47;
if ($category_id == 36) return 90;
if ($category_id == 37) return 91;
return 47; /* default if nothing else matches */
///////////////////////////////////
It was working 100%, but then I added 2 new pages in a category (36), and I am getting some php errors in the sections the modules are supposed to appear. In the sections the php error is, the default modules are being returned (47).
I have this exactly code twice, just for difference modules and positions.

Here is the error I am receiving, it is the same in both spots the metamod is placed:
Notice: Trying to get property of non-object in /home/xxxxxx/public_html/modules/mod_metamod/helper.php(524) : eval()'d code on line 26

Notice: Trying to get property of non-object in /home/xxxxxx/public_html/modules/mod_metamod/helper.php(524) : eval()'d code on line 27
Thanks in advance, and great mod!



Edited By:  pview
25-Mar-10 16:51:38

Administrator has disabled public posting
pview
Beginner Modder
ranks
useravatar
User Info

Re: Display modules based on Category, also a default if other

Fixed my own problem! Here is it for anyone else that may need it.

///////////////////////////////////
$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;
  }
} elseif ($option == "com_sefservicemap") {
return 47;
} else {
return 47;
}
/* 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 == 34) return 47;
if ($category_id == 36) return 90;
if ($category_id == 37) return 91;
return 47; /* default if nothing else matches */

////////////////////////////


Administrator has disabled public posting
metamodguy
useravatar
User Info

Re: Display modules based on Category, also a default if other

You beat me to it! Thanks for posting the solution. I hope it will help someone else in the same situation.

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

Administrator has disabled public posting

Board Info

Board Stats:   Total Users: 3086  Total Topics: 1195  Total Polls: 7  Total Posts: 4450  Total Posts Today: 2
User Info:   Newest User :  josemhg   Members Online: 1   Guests Online: 78
Online 
Salvage
Topic
New
Locked
Topic
New
Locked
Sticky
Active
New/Active
Sticky
Active
New/Active
New/Closed
New Sticky
Closed/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky Active Locked
Active/Sticky
Sticky/Locked
Sticky/Active/Locked