Control modules on JReviews pages

(4 votes, average 4.00 out of 5)

In the first example, we return different modules depending on whether jReviews (see ReviewsForJoomla.com) is on its “base” page or looking at a “category”. We can choose the modules according to category as seen below. Note that if you have SEO urls turned on, jReviews acts slightly differently to when they are not turned on, so the code below tests for both cases. It's not the most elegant way to handle it, but shows you how to handle the situation.

Other recipes on this page allow you to switch modules on or off depending on whether or not the displayed item is “featured” or not.

if ($option == "com_jreviews") {
 $url = preg_replace("#/$#",'', JRequest::getVar('url',''); 
 // Test if we are on the top level page, not in a section or category.
 // Don't forget to change the module number from 18 to something
 // appropriate for your site - or remove it altogether.
 if ($url == "") return 18;
 $parts = explode("/",$url);
 $last_part = $parts[count($parts)-1];
 $last_part = preg_replace("#_.*$#","",$last_part);
 
 /* Here's where you need to customise the recipe for your own use.
  * For each pair of "case" statements, put in one version with words
  * separated by ":" and one separated by "-".
  * Then return the module ID appropriate for that particular jReview.
  */
 switch ($last_part) {
   case "jreviews-category-list": // seo off
   case "jreviews:category:list": // seo on
     return 101; /* REPLACE 101 with appropriate module id */
   case "the-community": // seo off
   case "the:community": // seo on
     return 102; /* REPLACE 102 with appropriate module id */
   case "the-project": // seo off
   case "the:project": // seo on
     return 103; /* REPLACE 103 with appropriate module id */
   // add more as appropriate...
 }
}

Show a module only on a content page that has “featured” status:

if ($option == 'com_content' and $view == 'article' ) {
  $intid = (int)$id;
  $query = "select jrc.featured from #__jreviews_content jrc where jrc.contentid = $intid";
  $db->setQuery( $query, 0, 1 );
  $featured = $db->loadResult();
  if ($featured) return XXX; /* replace XXX with the module id of the module to display */
}
 

Show a module only on a content page that does not have “featured” status

if ($option == 'com_content' and $view == 'article' ) {
  $intid = (int)$id;
  $query = "select jrc.featured from #__jreviews_content jrc where jrc.contentid = $intid";
  $db->setQuery( $query, 0, 1 );
  $featured = $db->loadResult();
  if (!$featured) return XXX; /* replace XXX with the module id of the module to include */
}