Drupal 7 custom template files per content type

Very useful – got this from here where you can also find the one for D6.

As the comment suggests, if you have a content type called ‘blog’, you can create a template file to apply to nodes with this content type only called page–blog.tpl.php.

[sourcecode]

<?php
function themeName_preprocess_page(&$vars, $hook) {
if (isset(
$vars['node'])) {
// If the node type is "blog" the template suggestion will be "page--blog.tpl.php".
$vars['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $vars['node']->type);
}
}
?>
[/sourcecode]

 

Leave a Reply

Your email address will not be published. Required fields are marked *