Wednesday, February 1, 2012

Different Themes for Different nodes (pages) in Drupal

Steps to achieve:
1. Create 5 nodes i.e 5 pages in drupal
2. Enable 5 different themes in Admin Panel
3. Use the below code to switching the themes based on page id
4. Thats it..!

function yourmodule_init(){
  global $custom_theme;
 
  /* Page 1, using page id as 1 */
  if (arg(0) == "node" && arg(1) == 1){
    $custom_theme = "bluemarine";
  } 

 
  /* Page 2, using page id as 2 */
  if (arg(0) == "node" && arg(1) == 2){
    $custom_theme = "chameleon";
  }
 
  /* Page 3, using page id as 3 */
  if (arg(0) == "node" && arg(1) == 3){
    $custom_theme = "danland";
  }

  /* Page 4, using page id as 4 */
  if (arg(0) == "node" && arg(1) == 4){
    $custom_theme = "garland";
  }
 
  /* Page 5, using page id as 5 */
  if (arg(0) == "node" && arg(1) == 5){
    $custom_theme = "marvin";
  }

}

2 comments:

  1. Where to paste this code for bringing different theme based on each pages?

    ReplyDelete
  2. In your custom module i.e, .module file

    ReplyDelete

Followers