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.

 

$option == 'com_content' and specified sections/categories

$option == 'com_content' and specified sections/categories

Hi all,

I am looking for if statement to limit my modules only for com_content and limit only to few sections/categories by ID. What is the best if statement to achieve this

pembaris
Beginner Modder
ranks
useravatar
Offline
16 Posts
Administrator has disabled public posting

Re: $option == 'com_content' and specified sections/categories

Are you wanting the modules on the article pages, when the articles are in the specified categories/sections, or just on category/section list or blog pages?

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: $option == 'com_content' and specified sections/categories

hi Stephen,

Thanks for your reply and sorry for the confusion. What I meant was I wanted modules on articles pages, and only to those which are specified categories/sections.

Say I have 5 categories and 5 sections. I would only want to restrict to one of the categories (say category named "directory"). I would only want my modules to appear on that category and that alone.

Maybe some other modules on the other 4, but you get me smile

I have seen something here: http://www.metamodpro.com/metamod/recip … e-category

but pardon my noobness, I am no coder so i really couldnt digest that. However, I think restricting modules for article pages within restricted categories/sections, wouldn't be something like in the recipe, right?

Thats way over my head!

Thanks again. Please advise.

pembaris
Beginner Modder
ranks
useravatar
Offline
16 Posts
Administrator has disabled public posting

Re: $option == 'com_content' and specified sections/categories

Hi,

you got the right recipe page. Yes, the recipe on there is kind of big, but the part you need to customise is at the bottom. All the top part is simply getting hold of the category id out of the article that's being displayed.

Here's a slightly simplified version that restricts the module display to ONLY article pages. Just customise the "if" statements at the bottom:

Code:

$category_id = null;

if ( $option == "com_content" and $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 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 == 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 */
  return 50; /* default if nothing else matches */
}

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

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5933
Posts this week:
3
User Info:
 
Total Users:
4388
Newest User:
wilmer7878
Members Online:
2
Guests Online:
125


Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked