How can I change the output of my page.tpl.php for different content types, but within a single page.tpl.php file?

So so for a blog, rather than create a new file called page-blog.tpl.php, can I write add some php to my page.tpl.php which will show some html for a certain content type?

Something like this;

<?php if ($node-blog): ?> 
<h1> This is a page for the blog content type</h1>
<?php else: ?>   
<h1> This is a page for all content types except for blog</h1>
<?php endif; ?>   

Thanks

Comments

WorldFallz’s picture

Use if ($node->type == 'blog'):

jdln’s picture

Thanks WorldFallz
Ive expanded it to this, seems to be working fine.

<?php if ($node->type == 'blog'): ?> 
<!-- if node is blog ..... -->

<?php elseif ($node->type == 'page'): ?> 
<!-- if node is page ..... -->
       
<?php else: ?>   
<!-- if node is not a blog or a page -->

<?php endif; ?>   
jdln’s picture

How can I do the same thing for taxonomy pages?

Ive tried searching for this but i dont know what words to search for. Is there a name / resource for this stuff I should look at?

Thanks

WorldFallz’s picture

you mean format pages different for taxonomy terms? Yep. You'll want to get familiar with the Overriding themable output section of the handbook. Specifically the Core templates and suggestions and Working with template suggestions pages. Instead of putting all this logic in a single page.tpl.php file, you can setup different template files for different conditions.

For some ideas specific to taxonomy pages see http://mustardseedmedia.com/podcast/episode31.

jdln’s picture

Hi WorldFallz

I know about theming with a tpl.php file but im trying to do it in my page.tpl.php.

Is there a version of the code below that would recognize a taxonomy page, rather than the node type?
if ($node->type == 'blog'):

Thanks

WorldFallz’s picture

if (arg(0) == 'taxonomy'):

jdln’s picture

Thanks a lot.

Is there a good resource where I can find this sort of code or is it just one of those things you have to know?

WorldFallz’s picture

There's a snippets section in the handbook that has lots of good stuff but there will always be times when you need to improvise. I found that getting familiar with those snippets did help me to figure out things that weren't there though.

jdln’s picture

Ill do some reading. Thanks