We use cookies to improve our services and provide a better experience. By continuing to use this site, you agree with our Cookies Policy.

Tutorials
More than 400 step-by-step articles to guide you through online project development.
HomeTutorialsCMS TutorialsDrupalDrupal Themes

How to override the Drupal 7 taxonomy page template

By default Drupal uses it’s own template for displaying taxonomy pages. But in some cases default template might be useless if we want some custom layout. To achieve our goal we might need to implement custom made code in Drupal core functions. Here we will provide an example solution for how to display all or specific taxonomy pages.

1
2
3
4
5
6
7
8
9
<?php
function TEMPLATENAME_preprocess_page(&amp;$vars) {
if (arg(0) == 'taxonomy' &amp;&amp; arg(1) == 'term' &amp;&amp; is_numeric(arg(2))) {
$tid = arg(2);
$vid = db_query("SELECT vid FROM {taxonomy_term_data} WHERE tid = :tid", array(':tid' =&gt; $tid))-&gt;fetchField();
$variables['theme_hook_suggestions'][] = 'page__vocabulary__' . $vid;
}
}
?>

Use this code entry in theme’s template.php file for implementing the solution. In the case of success, Drupal 7 taxonomy page template should be¬†overridden. This will mean we are ready to create a custom set of taxonomy pages.

Make sure to always consult with Drupal documentation and community messages for more information how to achieve this functionality. There we might find more examples for how to implement custom taxonomy pages.

Rate this Tutorial:
No CommentsLeave a Comment

Other (195)

Popular Keywords