Drupal Taxonomy Tables Solution

First of all – YES – my logo is Drupal inspired, DUH!  I’m no longer working in Drupal and it’s changin’… gonna miss the face though.

Ok – here’s the orig. post below.

Categories as tables – YES!

As most seo’s know, Drupal is a GREAT open source cms. Not only is it highly customizable, but the seo features and contributed modules are making it better all the time.

But, I have been frustrated for a little while with a new web build for a client.

I desired to use Drupal’s taxonomy feature to categorize an online store. The default list format for category nodes insists on listing teasers in one column. I hit the Drupal forums and searched for a solution… to no avail – so I made it.

So, here’s the solution for all you to have and tinker with. I’m using version 4.7.6 – I have not tried this with 5.1 yet.

This code will force all teaser nodes to list in a table, columns are configurable in the code.

Open the taxonomy.module and change this:

line 1138-1149 from:

—————

function taxonomy_render_nodes($result) {
if (db_num_rows($result) > 0) {
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 .= t(‘There are currently no posts in this category.’);
}
return $output;
}

——————-

TO:

———————-
function taxonomy_render_nodes($result) {
$columns = 2;
$rows = 30;
$output = ‘<table class=”product-table”>’;
for ($i = 0; $node = db_fetch_object($result); $i++) {

if ($i % $columns == 0) {
$output .= ‘<tr>’;
}

$node = node_load($node->nid);
$teaser = true;
$page = false;

$node->body = str_replace(‘<!–break–>’, ”, $node->body);
if (node_hook($node, ‘view’)) {
node_invoke($node, ‘view’, $teaser, $page);
}
else {
$node = node_prepare($node, $teaser);
}
node_invoke_nodeapi($node, ‘view’, $teaser, $page);

$output .= ‘<td id=”nid_’. $node->nid .'”><p>’. l($node->title, “node/$node->nid”) .”</p><div>$node->teaser</div></td>\n”;

if ($i % $columns == $columns – 1) {
$output .= “</tr>\n”;
}
}

if ($i % $columns != 0) {
$output .= “</tr>\n”;
}
$output .= ‘</table>’;

if ($pager = theme(‘pager’, NULL, $rows * $columns, 0)) {
$output .= $pager;
}

return $output;
}
————————

This is adapted from the product.module in the ecommerce package. (credit due to the author of that module, Matt Westgate, for getting me in the right direction) Hope you get some benefit from this.

4 Responses to “Drupal Taxonomy Tables Solution”

  1. GcoderD February 15, 2007 at 2:04 pm #

    Awesome – THANKS! EXACTLY my frustration for a long time.
    GD

  2. Tim b May 28, 2007 at 2:45 pm #

    Found this in the Drupal forums, cool post thanks for the help, and good job crediting the inspiration! Noone ever does that.

    tb

  3. Martijn August 28, 2007 at 6:51 am #

    Hi,

    Could you please build a patch for 5.1.
    I am very curious how this works for drupal 5.1.

    Thanks!
    Martijn

  4. Knox August 28, 2007 at 8:57 pm #

    I will certainly do so with my next drupal progect and will let you know when I have it. Could be a few months so – sorry.

    Hey, if you come across one let us know here! :)

Leave a Reply