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:
- /**
- * Override or insert PHPTemplate variables into the templates.
- */
- function phptemplate_preprocess_page(&$vars) {
- // Add per content type pages
- if (isset($vars['node'])) {
- // Add template naming suggestion. It should alway use hyphens.
- // If node type is "custom_news", it will pickup "page-custom-news.tpl.php".
- $vars['template_files'][] = 'page-'. str_replace('_', '-', $vars['node']->type);
- }
- }
Thanks dvessel
Technology:
Comments
Code Monkey (not verified)
Thu, 07/09/2009 - 19:34
Permalink
Thank you!!
Thank you!!
Code Monkey (not verified)
Sat, 04/09/2011 - 23:38
Permalink
Thanks, I found this very
Thanks, I found this very helpful.
Entering the original function as is breaks many portions of the admin section, but if you rename the "phptemplate" portion of the function name to "mysite" where it is the name of your site it works perfectly.
CoolGoose
Mon, 04/11/2011 - 22:23
Permalink
The recommended way is to
The recommended way is to replace "phptemplate" with the name of your theme.
Code Monkey (not verified)
Tue, 09/22/2009 - 00:11
Permalink
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
Code Monkey (not verified)
Wed, 09/22/2010 - 05:53
Permalink
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
John Larysz
Thu, 11/26/2009 - 02:36
Permalink
This worked greart for me.
This worked greart for me. I've been looking for hours!
Code Monkey (not verified)
Sun, 02/14/2010 - 11:09
Permalink
Thank you thank you thank
Thank you thank you thank you! What an elegant and slim solution, just what I needed!
Code Monkey (not verified)
Wed, 04/21/2010 - 23:29
Permalink
many thanks
many thanks
Code Monkey (not verified)
Thu, 07/15/2010 - 14:38
Permalink
Don't forget to Clear Cache!
Don't forget to Clear Cache!
Code Monkey (not verified)
Wed, 08/18/2010 - 20:02
Permalink
Thank you so much, I have
Thank you so much, I have been trying to solve this problem for hours now!
Cheers!
Code Monkey (not verified)
Fri, 10/01/2010 - 05:36
Permalink
Worked like a charm...
Worked like a charm... Thanks!
Code Monkey (not verified)
Sat, 10/02/2010 - 08:03
Permalink
That is a deadly "Empty
That is a deadly "Empty Cache". Waste sometime before I found @cool_qosys comment.
Code Monkey (not verified)
Fri, 11/05/2010 - 22:31
Permalink
Bloody marvelous! Thanks!
Bloody marvelous!
Thanks!
Code Monkey (not verified)
Thu, 11/18/2010 - 12:21
Permalink
Third class
Third class
Code Monkey (not verified)
Mon, 12/27/2010 - 01:27
Permalink
Awesome great post !
Awesome great post !
Code Monkey (not verified)
Tue, 01/04/2011 - 05:03
Permalink
Thank you! Worked smoothly!
Thank you! Worked smoothly!
Code Monkey (not verified)
Thu, 01/06/2011 - 06:10
Permalink
thanks worked perfectly
thanks worked perfectly
Code Monkey (not verified)
Wed, 03/23/2011 - 18:31
Permalink
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
CoolGoose
Wed, 03/23/2011 - 18:35
Permalink
node-[name].tpl.php
node-[name].tpl.php
Code Monkey (not verified)
Wed, 03/23/2011 - 19:17
Permalink
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.
CoolGoose
Thu, 03/24/2011 - 16:59
Permalink
Ah, unfortunately you can't
Ah, unfortunately you can't do that easily.
One solution would be to split your existing page.tpl in header/footer parts and include them.
Code Monkey (not verified)
Thu, 03/24/2011 - 18:50
Permalink
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.
CoolGoose
Thu, 03/24/2011 - 18:52
Permalink
Thanks a lot for the update
Thanks a lot for the update ;). Nice snippet.
Pages
Add new comment