Drupal 6 Custom content type page theme

If you ever wondered how to change the page.tpl.php for a custom content type you've found out that by default Drupal 6 doesn't know how to do it.

It's "fixed" easily by adding the following code:

  1. /**
  2.  * Override or insert PHPTemplate variables into the templates.
  3.  */
  4. function phptemplate_preprocess_page(&$vars) {
  5.   // Add per content type pages
  6.   if (isset($vars['node'])) {
  7.     // Add template naming suggestion. It should alway use hyphens.
  8.     // If node type is "custom_news", it will pickup "page-custom-news.tpl.php".
  9.     $vars['template_files'][] = 'page-'. str_replace('_', '-', $vars['node']->type);
  10.   }
  11. }

Thanks dvessel

Technology: 

Comments

hhm... its not working for

hhm... its not working for me. i have a content type 'affiliate' and wanted to call a template 'page-node-affiliate.tpl.php' base on node type('affiliate').

i only received a blank page...

please help...

thanks,

vsotto

You've got the wrong naming

You've got the wrong naming convention. You can create a template for a page and/or a node. If you want a page, then it's page-[name].tpl.php and if you want to only change the node layout then you need to use node-[name].tpl.php

HELP!. It works but replaces

HELP!. It works but replaces the entire page template with the new template. I just want to replace the content portion of it, thus keeping header, footer, etc.

Any ideas?
thanks

Sorry I was not completeley

Sorry I was not completeley specific.
node-[name].tpl.php works for content types but not for taxonomy terms which is my problem. and all the solutions I have tried replace the entire page code not just the content portion of it.

thanks a lot.

Got It! Thanks a lot for your

Got It!
Thanks a lot for your answer, however I just figured out the answer to my problem, in case anybody is looking for the same issue here's what I did:

function mysite_preprocess_page(&$vars, $hook){
if($hook == 'page' && arg(0) == 'taxonomy' && arg(1) == 'term'){
$vars['content'] = theme('custom_node_taxonomy', $vars['content']);
}
}

and then implement the selected theme into the mysite_theme()

Now I can use my custom tpl to edit term pages. Maybe not the most efficient solution but works fine

cheers.

Pages

Add new comment