Although it was easy to find some info online about how to theme other stuff (e.g. search results), it is impossible to find a straightforward article about how to theme the output of a taxonomy/term/247 page?
How can I do it?
Although it was easy to find some info online about how to theme other stuff (e.g. search results), it is impossible to find a straightforward article about how to theme the output of a taxonomy/term/247 page?
How can I do it?
The taxonomy page is not magic in any that it requires something special to theme it. There's a template file, a preprocess function and some theming functions, much like any page.
If you would like to control the output of the default taxonomy page which is a bit raw, you can use views to overwrite the default page. You could then use views to only show node teasers, do some custom ordering, use a pager etc.
If you want to do something more specific you should edit your question to tell us what you want to do.
In Drupal 6, you can make use of node-taxonomy.tpl.php
and page-taxonomy-term.tpl.php
files in your theme to template taxonomy pages considering that the second one is the wrapper for the first. Behave node-taxonomy.tpl.php
like node.tpl.php
and page-taxonomy-term.tpl.php
like page.tpl.php
. for example:
page-taxonomy-term.tpl.php
<?php require 'header.tpl.php'; ?>
<body class="<?php echo $body_classes; ?>">
<div id="page">
<?php require 'page-navigation.tpl.php'; ?>
<div id="main">
<h2>Taxonomy term page</h2>
<div class="taxonomy-content">
<?php if ($tabs): echo '<div id="tabs-wrapper" class="clear-block">'; endif; ?>
<?php if ($title && !$node): echo '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>
<?php if ($tabs): echo '<ul class="tabs primary">'. $tabs .'</ul></div>'; endif; ?>
<?php if ($tabs2): echo '<ul class="tabs secondary">'. $tabs2 .'</ul>'; endif; ?>
<?php if ($show_messages && $messages){ echo $messages; } ?>
<?php echo $help; ?>
<?php echo $content; // contains the output of node-taxonomy.php, that's why I call this wrapper template file. ?>
</div> <!-- #taxonomy-content -->
</div> <!-- #main -->
</div> <!-- #page -->
<?php echo $closure; ?>
</body>
<?php require 'page-footer.tpl.php'; ?>
node-taxonomy.tpl.php
<div id="node-<?php echo $node->nid; ?>" class="node<?php if($sticky) echo ' sticky'; ?><?php if(!$status) echo ' node-unpublished'; ?>">
<div class="taxonomy-node">
<div class="node-body">
<a class="node-title" href="<?php echo $node_url ?>" title="<?php echo $title ?>">
<?php echo $title ?>
</a>
<span class="node-cck-field">
<?php echo $node->field_cck_blah[0]['view']; ?>
</span>
</div>
</div>
</div>
Well, I've forgot to inculde the most important part, so it was getting negative points! node-taxonomy.tpl.php
is not known for drupal by default so we have to introduce this as a template suggestion in the template.php
file of the theme, here we go:
/**
* Adding custom PHPTemplate suggestions on taxanomy pages.
*
* @param $vars
* A sequential array of variables to pass to theme template.
*/
function phptemplate_preprocess_node(&$vars) {
if(arg(0) == 'taxonomy'){
$suggestions = array('node-taxonomy'); //So, node-taxonomy.tpl.php will be known afterwards.
$vars['template_files'] = array_merge($vars['template_files'], $suggestions);
}
}
Also there is a taxonomy-term.tpl.php
, regarding Drupal 7.
Dont' forget to use check_plain()
& check_url()
on data outputs.
page-taxonomy-term.tpl.php is working but node-taxonomy.tpl.php is not working