Fix for make node cck fields into a table

  1. /**
  2.  * return cck fields formatted as table
  3.  */
  4. function phptemplate_content_format_table($node){
  5.   // get fields
  6.   $fields = content_fields(NULL, $node->type);
  7.   $header = array('', '');
  8.   $rows = array();
  9.   // loop through and check if field is set in node
  10.   foreach($fields as $fieldname => $field){
  11.     $row = array();
  12.     if(! empty($node->{$fieldname}[0]['value'])){
  13.       // make row of label and value
  14.       $row[] = array('data'=>$field['widget']['label'], 'class'=>'field-label');
  15.       // handle multiple values
  16.       foreach($node->{$fieldname} as $key => $value){
  17.         if(isset($node->{$fieldname}[$key]['view'])){
  18.           $row[] = array('data'=>$node->{$fieldname}[$key]['view'], 'class'=>'field-item');
  19.         }else{
  20.           $row[] = array('data'=>content_format($fieldname, $node->{$fieldname}[$key]), 'class'=>'field-item');
  21.         }
  22.       }
  23.       $rows[] = $row;
  24.     }
  25.   }
  26.   return theme('table', $header, $rows, array('class'=>'cck-table'));
  27.   //var_dump($fields);
  28. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.