I need to show a different taxonomy/term/id page depending on what term/id is being loaded. In my example, I want the taxonomy/term/id page to only show the node thumbnail if the term/id is from a certain content type. In order to accomplish this, I have manually hard coded the taxonomy_render_nodes function located in taxonomy.module.

Is there a better way to do this? Perhaps overriding somehow within the template.php or creating a module?

Comments

nevets’s picture

It sound like you want one or more content types to display differently when displayed on pages of the form taxonomy/term/id.

You could either modify node.tpl.php if it applies to all content types or if just some content types make a node-{content type}.tpl.php file and modify those templates. In general one solution would be to modify them something like this

<?php  if ( arg(0) == 'taxonomy' && arg(1) == 'term' ) { ?>
PHP code/HTML for special case
<?php } else { ?>
Existing PHP code/HTML in file
<?php} ?>
v1nce’s picture

Modifying the node-{content type}.tpl.php file does not modify how the taxonomy/term/xx page displays. The node object is being loaded within the taxonomy_render_nodes() function and then loaded with node_view().

<?php
while ($node = db_fetch_object($result)) {
  $output .= node_view(node_load($node->nid), 1);
}
?>

I am having to create a sql query to pull all the taxonomy term id's of one content type, then check if the current taxonomy/term/xx page is one of these term id's. If so, we display the image thumbnail only. Here is my taxonomy_render_nodes() modified code from the taxonomy.module:

<?php 
function taxonomy_render_nodes($result) {
  if (db_num_rows($result) > 0) {
    // Show only images for collection item content types on the taxonomy page
	// Pull all free tagged terms in the collection item content type 
    $sql = 'SELECT DISTINCT(t.tid) FROM {content_type_collection_item} c, term_node t WHERE c.nid = t.nid';
    $sqlresult = db_query($sql);
    while ($sqlobject = db_fetch_object($sqlresult)) {
      $collection_item_terms[] = $sqlobject->tid;
    }
    // Now check if we are on a taxonomy term page from arg(2) by checking the list of terms pulled from above sql
    if (in_array(arg(2), $collection_item_terms)) {
      while ($node = db_fetch_object($result)) {
        $nodeload = node_load($node->nid);
        // Display image only with hyperlink to node
        $output .= '<div class="taxonomy_collection_item_image"><a href="/node/'. $nodeload->nid .'">'. '<img src="/files/imagecache/collectionitem_thumb/'. $nodeload->field_image[0]['filepath'] .'" title="'. $nodeload->field_image[0]['title']. '" alt="'. $nodeload->field_image[0]['alt'] .'" /></a></div>';
      }
    } else { 
     while ($node = db_fetch_object($result)) {
       $output .= node_view(node_load($node->nid), 1);
     }
    }
    $output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0);
  }
  else {
    $output .= '<p>'. t('There are currently no posts in this category.') .'</p>';
  }
  return $output;
}
?>

What is the correct Drupal way to modify this code?
-----------------------------------------------------------------
Petafoo - We Love Animals

nevets’s picture

Calling node_view invokes the approriate tpl.php file so one can add a test there that does different formatting based on path. Similiar to what you have but it moves the logic into the tpl.php file

v1nce’s picture

Ahhhh, ok. I was loading the node object without node_view() if the page was on a taxonomy/term/xx within the sql query result. So, when I was editing the node-{content-type}.tpl.php file and not seeing any changes this was throwing me off.

Editing the node-{content-type}.tpl.php file works perfectly. Thank you nevets!
-----------------------------------------------------------------
Petafoo - We Love Animals

andrabr’s picture

This seems to work: http://drupal.org/node/67548

What really bothers me though is that I do not understand what processes URLs like taxonomy/term/1 - it seems like (at least in my installation) it is NOT taxonomy_term_page($term) in taxonomy module (I even tried deleting the function completely to make sure - nothing changes).

It is a mystery.

A>

TapSkill’s picture

Just to be of help if I can be, I know this code works in a template

 if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)) && arg(2)==5) {
//what the taxonomy term's page looks like, 5 is just an example
} else {
//what anything else looks like
} 

but does it work within the render function?

I want a solution for this, because I hate the Catalog module. Catalog makes the product nodes appear in a nice table layout, but it doesn't overwrite the taxonomy page, so you have extra pages to worry about. Also, Catalog messes up PathAuto, because both Catalog and Taxonomy pages share the same alias, making it append a zero (0). I just want to have a nice table grid for nodes of a specific term id or vocabulary... or node type, whichever is easier.

---
I have created and maintained countless Drupal-powered sites and have made heavy modifications to modules on a site-by-site basis. I am an illustrator, a game developer, and a web developer. I also stream on Twitch in my spare time.

nevets’s picture

You could use views, in Drupal 5 (views 1) there is an extra module that provides a grid, in Drupal 6, views 2 comes with a grid style. Since you can override the default taxonomy terms with views this could meet your needs.