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.

 

Receipes for templating section and categories only

Receipes for templating section and categories only

Greetings from South America!

First of all, great component! Thanks!

I'm newie with your component and I'm not PHP expert. I need to set a template for some sections and categories of my content only.

Can you give me a receipe or an example of how can I do this?

Thanks a lot and forgive me about my english

Gracias!

Óscar

oscarguzval
Beginner Modder
ranks
useravatar
Offline
1 Posts
Administrator has disabled public posting

Re: Receipes for templating section and categories only

Hola Óscar,

the quickest way to do this is with MetaTemplate Pro. That gives you a selector control where you can choose the sections and categories to use the template.

If you want to use the free MetaTemplate, then you need to code this in PHP code. Most of the "recipes" for MetaMod can be used for MetaTemplate, so this one is adapted from here: http://www.metamodpro.com/metamod/recip … e-category

Code:

$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 == 1 or $category_id == 2 or $category_id == 3) return true;
else return false;

Then you just need to set up the template name in the SUCCEED action.

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

Re: Receipes for templating section and categories only

Hello, i'm french ! Don't speack english very well :
Merci pour le code ci-dessous qui fonctionne très bien.
J'ai essayé de remplacer "category" par section mais évidemment cela ne fonctionne pas.
Cela ne doit pourtant par être très différent du code ci-dessous ?

Pouvez-vous m'aider ?
Merci.

metamodguy wrote:

Hola Óscar,

the quickest way to do this is with MetaTemplate Pro. That gives you a selector control where you can choose the sections and categories to use the template.

If you want to use the free MetaTemplate, then you need to code this in PHP code. Most of the "recipes" for MetaMod can be used for MetaTemplate, so this one is adapted from here: http://www.metamodpro.com/metamod/recip … e-category

Code:

$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 == 1 or $category_id == 2 or $category_id == 3) return true;
else return false;

Then you just need to set up the template name in the SUCCEED action.

Hope that helps,
Stephen

cannel
Beginner Modder
ranks
useravatar
Offline
1 Posts
Administrator has disabled public posting

Re: Receipes for templating section and categories only

Salut cannel,

this code is quite an old way of doing it. There's a quicker and easier way to detect sections now.

See this page:

http://www.metamodpro.com/metamod/recip … e-category

e.g.

// This rule will trigger on section pages (blog or list style) as well as category pages and article
// pages, where the section id of the section, category or article matches the one shown
if ( $content_genius->check("section_id = 15") ) return VVV;
if ( $content_genius->check("section_id = 17") ) return WWW;
if ( $content_genius->check("section_id = 18,19,20") ) return XXX; // combine several sections for one module id


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

Board Info

Board Stats:
 
Total Topics:
1684
Total Polls:
6
Total Posts:
5940
Posts this week:
1
User Info:
 
Total Users:
5161
Newest User:
kbmgkey234q
Members Online:
0
Guests Online:
501

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