5
votes

I'm trying to make a custom Taxonomy Term page in Drupal 7. I've created a page--taxonomy.tpl.php file in my templates folder. The file only prints out a message. I now try to force the template file by adding

function template_preprocess_page($variables) {
  if (arg(0) == 'taxonomy') {
    $variables['template_file'] = 'page--taxonomy-tpl';
  }
}

in my template.php, but it won't work. Can you help me? And if I get the custom page working, how do I fetch the nodes with this term (in page--taxonomy.tpl.php)? Thanks in advance.

4

4 Answers

9
votes

Try using this in your template.php:

function template_preprocess_page(&$variables) {
  if (arg(0) == 'taxonomy') {
    $variables['theme_hook_suggestions'][] = 'page__taxonomy';
  }
}
  • You need to pass $variables by reference, so add a & before it
  • template_file has changed to theme_hook_suggestions in Drupal 7
  • You don't need the -tpl in the template suggestion unless you want it to be a part of the filename like "page--taxonomy-tpl.tpl.php" which I don't think is what you want.

For more information, check out template_preprocess_page(), theme_get_suggestions() and Working with template suggestions

3
votes

Not sure if this would meet your requirements, but one of default D7 views - Taxonomy term - emulates Drupal core's handling of taxonomy/term pages. You could just enable it (it would automatically replace Drupal's core taxonomy URLs), and then do whatever you want with it, keeping original page structure, all blocks etc, using Views' page templates (see "Theming information" in "Advanced") and all other bells and whistles...

0
votes

Since you are using Drupal 7, you could also create a file name "taxnomy-term.tpl.php" and edit according to your needs.

See taxonomy-term.tpl.php

0
votes