1

I'm editing node.tpl.php, to apply custom theming when the site displays single nodes.

However, if I browse for a certain taxonomy term, the list of nodes presented is also affected by my changes.

Is there a way to theme just the single node pages?

1

3 Answers 3

1

You have access to the $page variable in your template file; if the node is being displayed in a full page this variable will be TRUE, and FALSE otherwise.

If you look at the core node.tpl.php file you can see it too takes advantage of this:

<?php if (!$page): ?>
  <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2>
<?php endif; ?>

That's used to only display a title on the node if it's not the main page display.

You also have access to a $view_mode variable if you want to be more specific about the particular view mode, e.g.:

<?php if ($view_mode == 'teaser'):
<?php // print something ?>
<?php endif; ?>
0
0

See same question here. Assign specific template to specific pages

See here Drupal 7 Theme Hook Suggestions

For nodes You can use

node--[type|nodeid].tpl.php
base template: node.tpl.php
Theme hook suggestions are made based on these factors, 

listed from the most specific template to the least. Drupal will use the most specific template it finds:

node--nodeid.tpl.php
node--type.tpl.php
node.tpl.php

Also Drupal 6 Template Suggestions

To use same tpl for multiple pages you need to use theme_preprocess_node Like

function theme_preprocess_node(&$vars, $hook) { $node = $vars['node']; if(in_array($node->nid), $myuids) $vars['template_file'] = 'your_template_file'; }

0

What version of Drupal? Take a look in the Theming Guide. Especially the Overview of theme files and Working with template suggestions. In the last link, you can see, when you install Theme Developer how the template file has to be named. The sum of all in D7: Drupal 7 Theme Hook Suggestions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.