[drupal-devel] more control over rending the list of nodes matching a taxonomy term?
This is my first post to the drupal-devel list so I'd like to say Hi first of all. I've been busy over the last week or two building up the theme for a site and developing a couple of custom modules. I'd like to have a bit more control over how the list of nodes matching a taxonomy term is presented. e.g. if I have a Drupal path such as taxonomy/term/6 I'd like to display the item teasers in a 2-column layout. I've been looking at the taxonomy_render_nodes function in taxonomy.module and at present this just appends the node_views together one after the other so doesn't seem to provide a way for me to add any additional HTML. Is there a suggested mechanism that already exists for doing something like this or should I look at making a modification to taxonomy_render_nodes (e.g. adding a theming function call) Thanks for any help, -Michael
I've been looking at the taxonomy_render_nodes function in taxonomy.module and at present this just appends the node_views together one after the other so doesn't seem to provide a way for me to add any additional HTML. Is there a suggested mechanism that already exists for doing something like this or should I look at making a modification to taxonomy_render_nodes (e.g. adding a theming function call)
welcome michael ... a theme call would be a nice enhancement.
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; }
participants (2)
-
Michael Josephson -
Moshe Weitzman