Different page templates depending on node type

The list of "template suggestions" for a template can be modified in your template.php file. The following snippet will add page template suggestions for node type for the current page. That allows you to for example define page-nodetype-news.tpl.php template which would apply to every page which node is news.

<?php
// theme overrides
function _phptemplate_variables($hook, $vars) {
  switch (
$hook) {
    case
'page':  
     
// Add page template suggestions based on node type.
     
if ($vars['node']) {
       
$suggestions[] = 'page-nodetype-'. $vars['node']->type;
       
// check to see if we're on the edit page
       
$path = explode('/', $_GET['q']);
        if (!(
arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit')) {
           
$vars['template_files'] = $suggestions;
    }
      }
    break;
  }
  return
$vars;
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.