Show modules on different "Mighty Content" pages

(14 votes, average 4.07 out of 5)

“Mighty Content” (link) is a Content Construction Kit. The following recipes allow you to target modules onto particular Mighty Content pages, such as category lists, article pages, and pages where the article is “featured”.

Modules should only appear on category “List” pages:

// replace XXX with the id of the module to return
if ( $option == 'com_resource'
  and $view == 'list'
) return XXX;

Modules should appear on all pages except category “List” pages:

// replace XXX with the id of the module to return
if ( $option != 'com_resource'
  or $view != 'list'
) return XXX;
 

Modules should only appear on category “List” pages, for certain categories:

// replace XXX with the id of the module to return
// replace AAA, BBB, CCC etc with the category ids to detect
if ( $option == 'com_resource'
  and $view == 'list'
) {
  $cat_id = JRequest::getVar('category_id');
  if ($cat_id == AAA
    or $cat_id == BBB
    or $cat_id == CCC
  ) return XXX;
}
 

Modules should only appear on article pages:

// replace XXX with the id of the module to return
if ( $option == 'com_resource'
  and $view == 'article'
) return XXX;
 

Modules should only appear on article pages, for “Featured” articles:

// replace XXX with the id of the module to return
$module_to_return = XXX;
if ( $option == 'com_resource'
  and $view == 'article'
) {
  $model = & JModel::getInstance('Record', 'ResModel');
  if ($model) {
    $model->_id = JRequest::getInt('article',0);
    $article = $model->getRecord();
    $found = $article->id && $article->published && $article->featured;
    if ( $found ) return $module_to_return;
  }
}
 

Modules should only appear on article pages, where the author of the article is the person viewing it:

// replace XXX with the id of the module to return
$module_to_return = XXX;
if ( $option == 'com_resource'
  and $view == 'article'
  and $user->id > 0
) {
  $model = & JModel::getInstance('Record', 'ResModel');
  if ($model) {
    $model->_id = JRequest::getInt('article',0);
    $article = $model->getRecord();
    $found = $article->id && $article->published && $user->id == $article->user_id;
    if ( $found ) return $module_to_return;
  }
}
 

Modules should only appear on article pages, where the author of the article is NOT the person viewing it:

// replace XXX with the id of the module to return
$module_to_return = XXX;
if ( $user->id == 0 ) return $module_to_return;
if ( $option == 'com_resource'
  and $view == 'article'
) {
  $model = & JModel::getInstance('Record', 'ResModel');
  if ($model) {
    $model->_id = JRequest::getInt('article',0);
    $article = $model->getRecord();
    $found = $article->id && $article->published && $user->id != $article->user_id;
    if ( $found ) return $module_to_return;
  }
}
 

Modules should appear on all pages except article pages:

// replace XXX with the id of the module to return
if ( $option != 'com_resource'
  or $view != 'article'
) return XXX;
 

Modules should appear only for certain articles, on the article pages:

// replace XXX with the id of the module to return
// replace AAA, BBB, CCC etc with the article ids to detect
$module_to_return = XXX;
if ( $option == 'com_resource'
  and $view == 'article'
) {
  $article_id = JRequest::getVar('article');
  if ( $article_id == AAA
    or $article_id == BBB
    or $article_id == CCC
  ) return $module_to_return;
}
 

Modules should appear on every page except for particular article pages:

// replace XXX with the id of the module to return
$module_to_return = XXX;
if ( $option != 'com_resource'
  or $view != 'article'
) return $module_to_return;
 
if ( $option == 'com_resource'
  and $view == 'article'
) {
  $article_id = JRequest::getVar('article');
  // replace AAA, BBB, CCC etc with the article ids to detect
  if ( $article_id != AAA
    and $article_id != BBB
    and $article_id != CCC
  ) return $module_to_return;
}