taxonomy-term.tpl.php works like nothing else in Drupal theming in that it essentially acts as a "header" for the listing of node teasers that come after it. This means there is effectively no way of theming how or where that template outputs its node listing, nor is there any way of really theming the node listing itself (At least, without resorting to, say, recreating the entire thing in Views).

This results in modules like http://drupal.org/project/disable_term_node_listings -- this shouldn't be necessary.

It would be so much easier to theme the list of items if taxonomy-term.tpl.php controlled that node listing -- the entirety of the default template looks as such:

<div id="taxonomy-term-<?php print $term->tid; ?>" class="<?php print $classes; ?>">

  <?php if (!$page): ?>
    <h2><a href="<?php print $term_url; ?>"><?php print $term_name; ?></a></h2>
  <?php endif; ?>

  <div class="content">
    <?php print render($content); ?>
  </div>

</div>

Really, it should probably look something like this:

<div id="taxonomy-term-<?php print $term->tid; ?>" class="<?php print $classes; ?>">

  <?php if (!$page): ?>
    <h2><a href="<?php print $term_url; ?>"><?php print $term_name; ?></a></h2>
  <?php endif; ?>

  <div class="content">
    <?php print render($content); ?>
  </div>

  <div class="items">
    <?php print render($items); ?>
  </div>

</div>

I'm not entirely sure how one would prevent this breaking existing sites that expect taxonomy-term.tpl.php to work as it currently does; any thoughts?

Comments

davidgenetic’s picture

Here's a workaround.

In your theme's template.php file you delete the nodes.

function THEMENAME_preprocess_page(&$vars)
{
  if (arg(0) == 'taxonomy' && arg(1) == 'term') {
    unset($vars['page']['content']['system_main']['nodes']);
  }
} 

In a custom module you retrieve the nodes and pass them as variables to your taxonomy-term.tpl.php template file.

 function MODULENAME_taxonomy_term_view($term, $view_mode, $langcode) {
  if ($term->vocabulary_machine_name == 'YOUR_VOCABULARY' && $view_mode == 'full') {
    $nids = taxonomy_select_nodes($term->tid);
    $nodes = node_load_multiple($nids);
    $term->content += node_view_multiple($nodes);
  }
} 

Use it in your taxonomy-term.tpl.php file as so:

echo render($content['nodes']);

I'm not sure about what happens to pagers etc. but it solved my problem.

davidgenetic’s picture

Issue summary: View changes

clarity

jibran’s picture

Status: Active » Closed (won't fix)

After #1857256: Convert the taxonomy listing and feed at /taxonomy/term/%term to Views we are not using taxonomy-term.tpl.php anymore in Drupal 8 and with views you can control the listing. This is a feature request and it doesn't apply to D8 and we are not accepting any feature requests for D7 so I am changing it to won't fix.