Custom Taxonomy Term page in Drupal 7
Solution 1
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 totheme_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
Solution 2
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...
Admin
Updated on June 09, 2022Comments
-
Admin almost 2 years
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.
-
Admin almost 13 yearsThanks mate - it works! However is this the best approach for a custom Taxonomy page? I would like to use all the regions of my template, and just make a custom "main content". Does this make sense? This template will just overwrite everything..
-
Laxman13 almost 13 years@s0mmer I think this is the way it has to be done. It is creating a layout for the whole page, not just the main content. So if you want all your normal regions and such, open page.tpl.php and copy/paste it into page--taxonomy.tpl.php, then from there you can customize however you like and will have your normal regions, etc