[drupal-devel] more control over rending the list of nodes matching a taxonomy term?

Michael Josephson josephson at gmail.com
Thu Jun 16 12:00:42 UTC 2005


Hi Moshe,

> welcome michael ... a theme call would be a nice enhancement.

Thanks for your reply. I've described the changes I've made below.
Does this look like it's done in the right approach and style for
Drupal?

If it looks OK I'll try to submit it as a patch to Drupal as the
default behaviour is unchanged until you provide your own version of
the theme functions.

Also.. I'm thinking that a similar change will be needed for flexinode
lists so am smarting to wonder if there's a more generic way to handle
this..

-Michael

1. Updated taxonomy_render_nodes so that instead of appending the
rendered node to $output it puts them in an array. The output then
becomes the result of calling the theme function with this list of
rendered nodes.

function taxonomy_render_nodes($result) {
  if (db_num_rows($result) > 0) {
    $nodes = array();
    while ($node = db_fetch_object($result)) {
      // $output .= node_view(node_load(array('nid' => $node->nid)), 1);
      array_push($nodes, node_view(node_load(array('nid' => $node->nid)), 1));
    }
    $output = theme('taxonomy_render_nodes', $nodes);
    $output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0);
  }
  else {
    $output .= t('There are currently no posts in this category.');
  }
  return $output;
}

2. Default implementation of the theme function which just
concatenates the nodes as before:

function theme_taxonomy_render_nodes($nodes) {
  $output = '';
  foreach ($nodes as $node) {
    $output .= $node;
  }
  return $output;
}

3. change to the taxonomy_term_page function so you can theme the
output (e.g. to control if you want the XML icon to be shown)

replace:

$output = taxonomy_render_nodes(taxonomy_select_nodes($tids,
$operator, $depth, TRUE));
$output .= theme('xml_icon', url("taxonomy/term/$rss_tids/$depth/feed"));

with :

$rendered_nodes = taxonomy_render_nodes(taxonomy_select_nodes($tids,
$operator, $depth, TRUE));
$xml_icon = theme('xml_icon', url("taxonomy/term/$rss_tids/$depth/feed"));
$output = theme('taxonomy_term_page', $rendered_nodes, $xml_icon);

4. default implementation of the taxonomy term page theme function
which just appends the xml icon to the end of hte rendered nodes list
(as before.)

function theme_taxonomy_term_page($rendered_nodes, $xml_icon) {
  // just append the XML icon to the end of the list of rendered nodes
  // for the default implementation.
  return $rendered_nodes . $xml_icon;
}



More information about the drupal-devel mailing list