I'm overriding my default taxonomy display with a file called page-taxonomy.tpl.php. It overrides all taxonomy pages but I only want to override vocabulary #3.

I tried things like page-taxonomy-3.tpl.php but that didn't work

I also tried to print variables with this, but I couldn't find any variables that conain the vocabulary used:

<?php
print '<pre>';
print_r(get_defined_vars());
print '</pre>';
?>

Any ideas on how to override the taxonomy page for just one vocabulary? Or to put a conditional statement in page-taxonomy.tpl.php that will only print a sentence if the page is displaying teasers from vocabulary #3?

Comments

esmailzadeh’s picture

subscribing

esmailzadeh’s picture

you can use arg(0) .. to access taxonomy tid then you can write a code like this:

$r=db_query("select tid from term_data where vid=%d",$your_selected_vid);
while($row=db_fetch_array($r)) $rows[]=$row['tid'];
if(in_array(arg(0),$rows))
{
do somthing
}
elvis2’s picture

The solution is to create a template file only if the term parent is x.

Example:

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
       
      if(arg(0) == 'taxonomy' && arg(1) == 'term') {
        $vid = taxonomy_get_term(arg(2));
       
        if($vid->vid == 1) {
          $variables['template_files'] = 'page-vocab-special';
        }
        else { // let's just create a generic but specific page for each vocab then
          $variables['template_files'] = 'page-vocab-' . $vid->vid;
        }
      }
       
      break;
  }
  return $vars;
}
Suzi’s picture

The easiest way is to name the file as such...

page-taxonomy-term-#.tpl.php

# of course being the taxonomy term # you want to display

l0calh0rst’s picture

But the question is how to get a special tpl for a VOCABULARY, not a term

EDIT: The answer was already there... kinda.
For drupal 6 this one works fine for me:

In template.php:

function phptemplate_preprocess_page(&$vars, $hook)
{
    // special page tpl for each vocabulary
    if ( arg(0) == 'taxonomy' && arg(1) == 'term' ) {
        $term = taxonomy_get_term(arg(2));
        $vars['template_files'][] = 'page-taxonomy-vocabulary-' . $term->vid;
    }

Now you can override the page.tpl for each vocabulary by it's id:

page-taxonomy-vocabulary-1.tpl.php
page-taxonomy-vocabulary-2.tpl.php
...

EDIT 2: didn't see this was for D5... sorry

derrynairn’s picture

I attempted this solution but the changes don't seem to have taken effect.

Is there anything site-specific I have to add to the template.php file in order for this to work? I am using D6.

l0calh0rst’s picture

Not that i know of. You did clear the cache after applying?

derrynairn’s picture

Thanks for your response l0calh0rst. I did clear the cache, yes.

When I entered the update on the template.php file, I suddenly couldn't access Views, Blocks and several other admin areas. Just white screens...

On the code which you have shown to enter in template.php, does the vocab number have to be inserted?

As in:

function phptemplate_preprocess_page(&$vars, $hook)
{
    // special page tpl for each vocabulary
    if ( arg(0) == 'taxonomy' && arg(1) == 'term' ) {
        $term = taxonomy_get_term(arg(2));
        $vars['template_files'][] = 'page-taxonomy-vocabulary-#' . $term->vid;
    }

Thanks, in advance.

l0calh0rst’s picture

The vocab id is stored in the $term object ($term->vid).

austinh7’s picture

The example is missing a "}" at the end.

derrynairn’s picture

Thanks for that austinh7! I have got it working now. It's amazing how something so simple can be the culprit.

IanNorton’s picture

taxonomy_get_term has become taxonomy_term_load & $vars['template_files'][] has become $variables['theme_hook_suggestions'][]

function phptemplate_preprocess_page(&$vars, $hook)
{
  if (arg(0) == 'taxonomy' && arg(1) == 'term' ){
    $term = taxonomy_term_load(arg(2));
    $variables['theme_hook_suggestions'][] = 'page-taxonomy-vocabulary-' . $term->vid;
  }
}

Ian Norton

ErikU’s picture

As already mentioned, there is a missing } . I just wanted to add that it is not good practice to add a hashtag into filenames.

Here is the code for all y'all who want to copy/paste it. Just remember that you use the Vocabulary ID not the name.
Example template file name: page-taxonomy-vocabulary-1.tpl.php

function phptemplate_preprocess_page(&$vars, $hook) {
    // special page tpl for each vocabulary
    if ( arg(0) == 'taxonomy' && arg(1) == 'term' ) {
        $term = taxonomy_get_term(arg(2));
        $vars['template_files'][] = 'page-taxonomy-vocabulary-' . $term->vid;
    }
}
skaught’s picture

cheers to this!